DropDownList使用UpdatePanel和ModalPopupExtender不会更改值

时间:2010-04-05 23:49:03

标签: asp.net drop-down-menu updatepanel ajaxcontroltoolkit modalpopupextender

问候,

我有一个asp.net网页,其中包含一个更新面板内的modalpopupextender。当我在弹出窗口中单击“确定”时,我可以从弹出窗口中获取文本框值,但是DropDownLists具有旧的/默认值,而不是我为它们选择的新值。

弹出窗口上的所有控件都设置为enableviewstate = true,autopostback = false(我只想在单击ok按钮时访问服务器,而不是每次更改弹出窗口的值)。

以下是相关代码。

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

客户端

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

。 。 。那么这里有一个WEBGRID。 。

这个模态popupextender在这里被破坏了。我无法获得stackoverflow来显示它。 它显示了这里的属性。 “         BackgroundCssClass = “modalBackground”         阴影效果=“真”         OkControlID = “btnEditOk”         CancelControlID =“btnEditCancel”Animations =“”&gt;                 

        </ContentTemplate>
</asp:UpdatePanel>

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

服务器端

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

1 个答案:

答案 0 :(得分:0)

检查您是否在每次回发时重新填充/重置DropDownLists,如Page_Init或Page_Load。

通常,你只想在!IsPostBack。

时才这样做