javascript ASP.net 按钮单击不使用 Jquery 模态对话框触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20111929/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 17:45:17  来源:igfitidea点击:

ASP.net Button on click not firing using Jquery Modal Dialog

c#javascriptjqueryhtmlasp.net

提问by Albert Laure

I have a div that is shown as a Modal dialog.

我有一个显示为模态对话框的 div。

<div id="div2" style="display: none;" title="Upload Prenda">
        <center>
            <br />
            Select File to Upload:
            <asp:FileUpload ID="PrendaFileUpload" runat="server" Width="345px" />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="PrendaFileUpload"
                ErrorMessage="File to be uploaded Required" ValidationGroup="X">*</asp:RequiredFieldValidator><br />
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                ShowSummary="False" ValidationGroup="X" />
            <br />
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            <asp:Button ID="uploadButton" runat="server" Text="Upload" OnClick="uploadButton_Click"
                 Width="100px" />
        </center>
    </div>

here is the jquery for it

这是它的 jquery

 <script type="text/javascript">
$(function() {
$( "#div2" ).dialog({
autoOpen: false,
modal:true,
resizable: false,
 height: 200,
width: 600
});
$( "#toggle" ).click(function() {
$( "#div2" ).dialog( "open" );
});
});
</script> 

the problem is after i press the button to activate the OnClick="uploadButton_Click"the method inside does not fire, any fix for this? sorry im just new in using jquery.

问题是我按下按钮激活OnClick="uploadButton_Click"里面的方法后没有触发,有什么解决办法吗?抱歉,我刚开始使用 jquery。

回答by Albert Laure

Well this is the answer that worked for me, im not using any update panel and this is what i used

嗯,这是对我有用的答案,我没有使用任何更新面板,这就是我使用的

adding this to the dialog declaration:

将此添加到对话框声明中:

  open: function(type,data) {
    $(this).parent().appendTo("form");
  }

found the answer in hereso if you want to know more about click the link beside :)

这里找到了答案,所以如果您想了解更多信息,请单击旁边的链接:)

回答by Daniel Anderson

The newer versions of JQueryUI use a slightly different convention. In your .dialog()declaration, add this is a parameter:

较新版本的 JQueryUI 使用略有不同的约定。在您的.dialog()声明中,添加这是一个参数:

appendTo: "form",

This fixes the issue for new versions of JQuery, since it builds the dialog box outside the scope of the ASP.NET form. Hope this helps newer users!

这解决了新版本 JQuery 的问题,因为它在 ASP.NET 表单范围之外构建对话框。希望这对新用户有所帮助!

回答by user5940155

This query will fire C# code from JQuery. I tested it:

此查询将从 JQuery 触发 C# 代码。我测试了一下:

 $(this).parent().appendTo($("form:first"));

回答by Tyler Durden

Try this solution: jQuery modal dialog with postbacks in ASP.NET

试试这个解决方案: jQuery modal dialog with postbacks in ASP.NET

This tells jQuery to append the dialog to the form tag rather than the end of the document.

这告诉 jQuery 将对话框附加到表单标签而不是文档的末尾。