<div style="display: none" id="CopyNews" title="Enter the newsletter details">
<div style="position: relative; height: 100%">
<br />
<asp:Label ID="MailType" runat="server" Text="type:" />
<asp:DropDownList ID="ddlDlgType" runat="server" AutoPostBack="true" />
<br />
<br />
<asp:Label ID="MailTitle" runat="server" Text=" title:" />
<asp:TextBox ID="txtTitle" runat="server" />
<br />
<br />
<div style="text-align: center;">
<asp:Button runat="server" ID="YesButton" Text="OK" />
<asp:Button runat="server" ID="CancelButton" Text="Cancel" />
</div>
</div>
</div>
<script>
function OpenNews() {
$("#CopyNews").dialog({
width: 'auto',
height: 'auto',
modal: true,
resizable: false,
position: 'center'
});
}
</script>
点击一个按钮后(在后面的代码中),我显示上面的对话框:
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "OpenNews();", true);
我的意图:
我确实想在代码隐藏中使用 DropDownList 值和单击确定按钮后的文本框值,显然,当单击取消按钮时,对话框应该关闭。
我怎样才能实现这些目标?
最佳答案
尽管您在对话框中使用了 div,代码隐藏行为仍然存在。因此,您通常可以在代码隐藏中访问该对象的属性。
您可以只处理 YesButton
(按钮 OK)的 OnClick
ASP.NET 事件并检查这些控件的值。请看下面的代码:
<asp:Button runat="server" ID="YesButton" Text="OK" OnClick="YesButton_Click" />
唯一的修改是你必须在 ddlDlgType
中设置 AutoPostBack="false"
,否则你的模态将消失,因为将发生回发。
要在单击“取消”时关闭,请处理 onClick javascript 事件并尝试以下操作:
$("#CopyNews").dialog( "close" );
关于javascript - 从对话框中获取值并在后面的代码中使用它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31674347/