无法在UpdatePannel中获取DropDownList控件

时间:2018-11-01 09:19:31

标签: javascript asp.net vb.net updatepanel

我的ASPX页中有一个UpdatePannel,里面有一些控件,其中有一个DropDownList。使用以下方法切换到“编辑模式”时,我需要从后面的代码中的DropDownList中删除ListItem:

 Protected Sub dvApplicationDetail_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewModeEventArgs) Handles dvApplicationDetail.ModeChanging
    Dim Result As DataSet
    Try
        If e.NewMode = DetailsViewMode.Insert Then
            dvApplicationDetail.ChangeMode(DetailsViewMode.ReadOnly)
        ElseIf e.NewMode = DetailsViewMode.Edit Then
            dvApplicationDetail.ChangeMode(DetailsViewMode.Edit)

            Dim PaymentReminders = CType(Me.dvApplicationDetail.FindControl("PayReminders"), DropDownList)

        End If
End Sub

但是我无法使用此方法获取DropDownList,因为尚未加载面板:

Dim PaymentReminders = CType(Me.dvApplicationDetail.FindControl("PayReminders"), DropDownList)

这是我为此提供的ASPX页面:

<asp:UpdatePanel ID="updatePanel5" runat="server">
                                                                <ContentTemplate>
                                                                    <asp:DetailsView ID="dvApplicationDetail" runat="server" CssClass="TbItemsVal" Width="100%"
                                                                        AutoGenerateEditButton="True" AutoGenerateRows="False" BackColor="White">
                                                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                                        <EditRowStyle Font-Bold="True" CssClass="TbItems" />
                                                                        <RowStyle BackColor="#EEE9CB" ForeColor="#333333" />
                                                                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                                                        <Fields>
                                                                                                                                                            <asp:TemplateField Visible="false">
                                                                                <headertemplate> 
                                                                                    Insured Accepts the<br />
                                                                                    <a href="#">Electronic Terms and Conditions?</a>
                                                                                </headertemplate>                                                                                    
                                                                                <ItemTemplate>
                                                                                    <%# Eval("AcceptTerms") %>                                                                                                                                                                               
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <%--<asp:TextBox ID="AcceptTerms" runat="server" Text='' />--%>
                                                                                    <asp:DropDownList ID="AcceptTerms" runat="server" onchange="changePaymentReminder()" Text='<%# Eval("AcceptTerms") %>' AutoPostBack="true" OnSelectedIndexChanged="AcceptTerms_SelectedIndexChanged">
                                                                                        <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
                                                                                        <asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
                                                                                        <asp:ListItem Text="No" Value="No"></asp:ListItem>
                                                                                    </asp:DropDownList>
                                                                                    <%--<asp:RegularExpressionValidator ID="REVAcceptTerms" runat="server" ControlToValidate="AcceptTerms" />--%>
                                                                                </EditItemTemplate>
                                                                                <HeaderStyle Font-Bold="True" />
                                                                                <ItemStyle Width="61%" />
                                                                            </asp:TemplateField>

                                                                            <asp:TemplateField HeaderText="Payment Reminders">                                                                                  
                                                                                <ItemTemplate> 
                                                                                    <%# Eval("B28_EMAIL_FLAG") %>                                                                                        
                                                                                </ItemTemplate>
                                                                                <EditItemTemplate>
                                                                                    <%--<asp:TextBox ID="AcceptTerms" runat="server" Text='' />--%>
                                                                                    <asp:DropDownList ID="PayReminders" runat="server" Text='<%# Eval("B28_EMAIL_FLAG") %>'>
                                                                                        <asp:ListItem Text="Select" Value="Select"></asp:ListItem>
                                                                                        <asp:ListItem Text="Text" Value="Text"></asp:ListItem>
                                                                                        <asp:ListItem Text="Email" Value="Email"></asp:ListItem>  
                                                                                        <asp:ListItem Text="Text&Email" Value="Text&Email"></asp:ListItem> 
                                                                                        <asp:ListItem Text="Declined" Value="Declined"></asp:ListItem>  
                                                                                    </asp:DropDownList>
                                                                                    <div style="vertical-align:top;display:inline-block;">
                                                                                        <table>
                                                                                            <tr>
                                                                                                <td></td>
                                                                                                <td><img id="imgWait" runat="server" src="../../Images/CircleBall.gif" style="display: none; text-align: center;" alt="" />
                                                                                                    <asp:Label ID="LblMsg" runat="server" BorderStyle="None" Width="215px" Font-Size="12px" ForeColor="Red" ></asp:Label></td>
                                                                                            </tr>
                                                                                        </table>
                                                                                    </div>
                                                                                    <%--<asp:CompareValidator id="CompareFieldValidator1" runat="server" ForeColor="Red" ControlToValidate="PayReminders" ValueToCompare="Select" Type="Integer" Operator="NotEqual" ErrorMessage="Please select a payment reminder type"></asp:CompareValidator >--%>
                                                                                </EditItemTemplate>
                                                                                <HeaderStyle Font-Bold="True" />
                                                                                <ItemStyle Width="61%" />
                                                                            </asp:TemplateField>
                                                                        </Fields>
                                                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                                        <AlternatingRowStyle BackColor="WhiteSmoke" ForeColor="#284775" />
                                                                        <CommandRowStyle CssClass="btnmain" HorizontalAlign="Center" Width="20px" Wrap="True"
                                                                            BorderStyle="Solid" BorderWidth="2px" />
                                                                    </asp:DetailsView>
                                                                    <asp:HiddenField ID="hidOrigEmail" runat="server" />
                                                                    <asp:Panel ID="PnlContactUpdateError" HorizontalAlign="Center" runat="server">
                                                                        <asp:Label ID="LblContactUpdateError" runat="server" ForeColor="Red"></asp:Label>
                                                                    </asp:Panel>
                                                                </ContentTemplate>
                                                            </asp:UpdatePanel>

我也尝试通过以下脚本使用javasciprt进行操作:

var prddl = document.getElementById('ctl00_ContentPlaceHolder2_dvApplicationDetail_PayReminders');
    $(window).bind("load", function () {
        prddl.remove(4);
    });

但是没有机会! 你有什么主意吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

我成功解决了这个问题,并希望与您分享解决方案。 解决方案只是添加代码以在页面的Prerender()函数中获取DropDownList,因为这是在呈现页面之前要调用的最后一个事件。

谢谢