C# ASP.NET AJAX 控件工具包:显示一个 ModalPopup 然后执行 PostBack
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/896519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET AJAX Control Toolkit: Show a ModalPopup and then do PostBack
提问by VansFannel
I want to show a modal popup when a user click on an asp button. The user must select an option of a panel. The value of the option selected must be saved to an input hidden and then the asp.net button must doa PostBack.
当用户单击 asp 按钮时,我想显示一个模态弹出窗口。用户必须选择面板的选项。选择的选项的值必须保存到隐藏的输入,然后在asp.net按钮必须做一回发。
Can I do that?
我可以这样做吗?
Thank you!
谢谢!
采纳答案by VansFannel
Finally, I've decided to use jQuery to show a ModalPopUp. The following question has the answer to this question:
最后,我决定使用 jQuery 来显示 ModalPopUp。下面的问题可以回答这个问题:
jQuery UI's Dialog doesn't work on ASP.NET
If you are not agree, tell me.
如果您不同意,请告诉我。
回答by David Glenn
Add your Button or LinkButton
添加您的 Button 或 LinkButton
<asp:Button ID="MyButton" Text="Click Here" runat="server" />
Add a Panel to hold your options with a DropDownList
添加面板以使用 DropDownList 保存您的选项
<asp:Panel ID="MyPanel" runat="server">
<asp:DropDownList ID="MyDropDown" runat="server">
<asp:ListItem Value="1" Text="Option 1" />
</asp:DropDownList>
<asp:Button ID="SaveBtn" Text="Save" OnClick="Save_Click" runat="server" />
<asp:Button ID="CancelBtn" Text="Cancel" runat="server" />
</asp:Panel>
Add your ModelPopupExtender
添加您的 ModelPopupExtender
<act:ModalPopupExtender ID="Mpe1" TargetControlID="MyButton"
CancelControlID="CancelBtn" PopupControlID="MyPanel" runat="server" />
Then add your code behind to the SaveBtn Button
然后将您的代码添加到 SaveBtn 按钮
public void SaveBtn_Click(object sender, EventArgs e) {
string selectedOption = MyDropDown.SelectedValue;
}
回答by Tim Scarborough
It is possible for a ModalPopupExtender to be displayed using a postback. You'll need an invisible target control. The extender is attached to this hidden control.
可以使用回发显示 ModalPopupExtender。您将需要一个不可见的目标控件。扩展器连接到这个隐藏控件。
<asp:Button runat="server" ID="btnShowModal" Text="Show"
OnClick="btnShowModal_Click" />
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolKit:ModalPopupExtender ID="Modal1" runat="server"
TargetControlID="HiddenForModal" PopupControlID="PopupPanel" />
In your message handler in code-behind, you'll show the ModalPopupExtender:
在代码隐藏的消息处理程序中,您将显示 ModalPopupExtender:
Modal1.Show();
And in the code you're using to dismiss the Modal, call the ModalPopupExtender's Hide function:
在您用来关闭 Modal 的代码中,调用 ModalPopupExtender 的 Hide 函数:
Modal1.Hide();
I use this method for showing a modal that displays detailed data that I retrieve from a database based on what's selected in a GridView.
我使用此方法显示一个模式,该模式显示我根据在 GridView 中选择的内容从数据库中检索的详细数据。