Search code examples
javascriptasp.netvb.netupdatepanel

Cannot get the DropDownList control in UpdatePannel


I have an UpdatePannel in my ASPX page which has some controls inside, among the controls I have a DropDownList. I need to remove a ListItem from the DropDownList in code behind when I switch to Edit Mode using the following Method:

 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

But I cannot get the DropDownList using this method, since the Panel is not loaded yet:

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

Here is the ASPX page I have for this:

<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>

I tried also to use javasciprt to do that using this script:

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

But no chance ! Do you have any idea please?

Thank you in advance.


Solution

  • I succeeded to resolve this, and would like to share the solution with you. The solution was simply to add code to get the DropDownList inside Prerender() function of the page, since it's the last event to call before the page is rendered.

    Thank you,