gpt4 book ai didi

asp.net - DropDownList 值不随 UpdatePanel 和 ModalPopupExtender 而改变

转载 作者:行者123 更新时间:2023-12-01 15:25:02 25 4
gpt4 key购买 nike

问候,

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

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

这是相关代码。

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

客户端

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

这里的模态弹出扩展器被破坏了。我无法让 stackoverflow 正确显示它。它显示了这里的属性。“ BackgroundCssClass="modalBackground" 投影=“真” OkControlID="btnEditOk" CancelControlID="btnEditCancel"动画="">

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

最佳答案

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

通常,只有在 !IsPostBack 时,您才想这样做。

关于asp.net - DropDownList 值不随 UpdatePanel 和 ModalPopupExtender 而改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2581832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com