DropDownList Value not changing with UpdatePanel and ModalPopupExtender

Posted by Richard on Stack Overflow See other posts from Stack Overflow or by Richard
Published on 2010-04-05T23:49:02Z Indexed on 2010/04/05 23:53 UTC
Read the original article Hit count: 415

Greetings,

I have an asp.net webpage with an modalpopupextender inside of an updatepanel. When I click Ok on the popup, I can get the textbox values from the popup just fine, but the DropDownLists have the old/default value, not the new value I have selected for them.

All the controls on the popup are set to enableviewstate = true, and autopostback = false (I just want to make the trip to the server when I click the ok button, not every time I change the value of the popups).

Here is the relevant code.

==========================

Client Side

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>


        <asp:Panel ID="EditIssuePanel" runat="server" CssClass="modalPopup" Style="display:block;" >

            <table style="width:500px;">
                <tr style="height:50px;">
                    <td colspan="2" align="center">
                        <asp:Label ID="lblEditIssueHeader" runat="server" Text="Edit Issue"></asp:Label>
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn">
                        <asp:Label ID="lblIssueName" runat="server" Text="Name:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                        <asp:TextBox ID="txtName" runat="server" Width="250px" MaxLength="50"></asp:TextBox>
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn">
                        <asp:Label ID="lblDescription" runat="server" Text="Description:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                        <asp:TextBox ID="txtDescription" runat="server" Width="250px" MaxLength="1000"></asp:TextBox>
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn">
                        <asp:Label ID="lblType" runat="server" Text="Type:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                        <asp:DropDownList ID="ddlType" runat="server">
                            <asp:ListItem Selected="True" Value="B">Bug</asp:ListItem>
                            <asp:ListItem Value="R">Request</asp:ListItem>
                            <asp:ListItem Value="O">Other</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn">
                        <asp:Label ID="lblStatus" runat="server" Text="Status:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                        <asp:DropDownList ID="ddlStatus" runat="server">
                            <asp:ListItem Selected="True" Value="L">Logged</asp:ListItem>
                            <asp:ListItem Value="I">In Process</asp:ListItem>
                            <asp:ListItem Value="C">Complete</asp:ListItem>
                        </asp:DropDownList>
                        &nbsp;
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn">
                        <asp:Label ID="lblPriority" runat="server" Text="Priority:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                            <asp:DropDownList ID="ddlPriority" runat="server" EnableViewState="true" AutoPostBack="false">
                            <asp:ListItem Selected="True" Value="L">Low</asp:ListItem>
                            <asp:ListItem Value="M">Medium</asp:ListItem>
                            <asp:ListItem Value="H">High</asp:ListItem>
                        </asp:DropDownList>
                        &nbsp;</td>   
                </tr>
                <tr style="height:30px">
                    <td class="labelscolumn">Logger</td>
                    <td class="datacolumn">
                        <asp:Label ID="lblEnteredByClientUserID" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn">
                        <asp:Label ID="lblDateResolutionRequested" runat="server" Text="Requested Complete Date:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                        <igsch:WebDateChooser ID="wdcRequestCompleteDate" runat="server">
                        </igsch:WebDateChooser>
                        &nbsp;</td>

                </tr>
                <tr style="height:30px">
                    <td class="labelscolumn">Logged Date</td>
                    <td class="datacolumn">
                        <asp:Label ID="lblLoggedDate" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr style="height:30px">
                    <td class="labelscolumn">In Process Date</td>
                    <td class="datacolumn">
                        <asp:Label ID="lblInProcessDate" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr style="height:30px">
                    <td class="labelscolumn">Resolved Date</td>
                    <td class="datacolumn">
                        <asp:Label ID="lblResolvedDate" runat="server" Text=""></asp:Label>
                    </td>
                </tr>
                <tr style="height:30px;">
                    <td class="labelscolumn" valign="top">
                        <asp:Label ID="lblEmailCCList" runat="server" Text="Email CC:"></asp:Label>
                    </td>
                    <td class="datacolumn">
                        <asp:TextBox ID="txtEmailCCList" runat="server" MaxLength="2000" Rows="0" 
                            TextMode="MultiLine" Height="83px" Width="250px"></asp:TextBox>
                        &nbsp;</td>

                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblIssueID" runat="server" Text="" Visible="false"></asp:Label>
                        <asp:Label ID="lblClientID" runat="server" Text="" Visible="false"></asp:Label>
                    </td>
                    <td align="right">
                        <asp:Button ID="btnEditOk" runat="server" Text="Ok" onclick="btnEditOk_Click"/>&nbsp;&nbsp;
                        <asp:Button 
                            ID="btnEditCancel" runat="server" Text="Cancel" onclick="btnEditCancel_Click" />&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>

                </tr>
            </table>

        </asp:Panel>

. . . THEN THERE IS A WEBGRID HERE. . .

This modal popupextender here got mangled. I cant get stackoverflow to show it right. It shows the properties here though. " BackgroundCssClass="modalBackground" DropShadow="true" OkControlID="btnEditOk" CancelControlID="btnEditCancel" Animations="">

        </ContentTemplate>
</asp:UpdatePanel>

=========================================

Server Side

protected void btnEditOk_Click(object sender, EventArgs e) { IssueDAO issueDAO = new IssueDAO();

    string client = "Eichleay";
    string name = null;
    string description = null;
    string type = null;
    string status = null;
    DateTime? resolvedDate = null;
    string enteredByClientUserName = User.Identity.Name.ToString();
    DateTime? loggedDate = DateTime.Now;
    DateTime? inProcessDate = null;
    DateTime? completeDate = null;
    DateTime? requestCompleteDate = null;
    string priority = null;
    int? prioritySort = null;
    string emailCCList = null;

    name = txtName.Text.Substring(txtName.Text.Length > 0 ? 1 : 0, (txtName.Text.Length > 0 ? txtName.Text.Length : 1) - 1);
    description = txtDescription.Text.Substring(txtDescription.Text.Length > 0 ? 1 : 0, (txtDescription.Text.Length == 0 ? 1 : txtDescription.Text.Length) - 1);
    type = ddlType.SelectedValue;
    status = ddlStatus.SelectedValue;
    resolvedDate = string.IsNullOrEmpty(lblResolvedDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblResolvedDate.Text));
    inProcessDate = string.IsNullOrEmpty(lblInProcessDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblInProcessDate.Text));
    completeDate = string.IsNullOrEmpty(lblResolvedDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblResolvedDate.Text));
    requestCompleteDate = wdcRequestCompleteDate.Value == null ? null : string.IsNullOrEmpty(wdcRequestCompleteDate.Value.ToString()) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(wdcRequestCompleteDate.Value.ToString()));
    priority = ddlPriority.SelectedValue;
    emailCCList = txtEmailCCList.Text.Substring(txtEmailCCList.Text.Length > 0 ? 1 : 0, (txtEmailCCList.Text.Length > 0 ? txtEmailCCList.Text.Length : 1) - 1);

    if (lblEditIssueHeader.Text.Substring(0, 3) == "New")
    {
        issueDAO.InsertIssue(client,
                             name,
                             description,
                             type,
                             status,
                             resolvedDate,
                             enteredByClientUserName,
                             loggedDate,
                             inProcessDate,
                             completeDate,
                             requestCompleteDate,
                             priority,
                             prioritySort,
                             emailCCList);
    }
    else
    {
        Issue issue = new Issue(Convert.ToInt32(lblIssueID.Text), 
                                lblClientID.Text, 
                                txtName.Text.Substring(txtName.Text.Length > 0 ? 1 : 0, (txtName.Text.Length > 0 ? txtName.Text.Length : 1) - 1), 
                                txtDescription.Text.Substring(txtDescription.Text.Length > 0 ? 1 : 0, (txtDescription.Text.Length == 0 ? 1 : txtDescription.Text.Length) - 1), 
                                ddlType.SelectedValue, 
                                ddlStatus.SelectedValue, 
                                string.IsNullOrEmpty(lblResolvedDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblResolvedDate.Text)), 
                                lblEnteredByClientUserID.Text, 
                                string.IsNullOrEmpty(lblLoggedDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblLoggedDate.Text)), 
                                string.IsNullOrEmpty(lblInProcessDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblInProcessDate.Text)), 
                                string.IsNullOrEmpty(lblResolvedDate.Text) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(lblResolvedDate.Text)), 
                                string.IsNullOrEmpty(wdcRequestCompleteDate.Value.ToString()) == true ? null : new Nullable<DateTime>(Convert.ToDateTime(wdcRequestCompleteDate.Value.ToString())), 
                                ddlPriority.SelectedValue, 
                                null, 
                                txtEmailCCList.Text.Substring(txtEmailCCList.Text.Length > 0 ? 1 : 0, (txtEmailCCList.Text.Length > 0 ? txtEmailCCList.Text.Length : 1) - 1));

        issueDAO.UpdateIssue(issue);
    }

    //        wdgIssues.ClearDataSource();
    //        UpdatePanel1.Update();

    lblIssueID.Text = null;
    lblClientID.Text = null;
    txtName.Text = null;
    txtDescription.Text = null;
    ddlType.SelectedValue = null;
    ddlStatus.SelectedValue = null;
    lblLoggedDate.Text = null;
    lblInProcessDate.Text = null;
    lblResolvedDate.Text = null;
    wdcRequestCompleteDate.Value = null;
    ddlPriority.SelectedValue = null;
    txtEmailCCList.Text = null;
}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about dropdownlist