从JqueryDialog调用VB子

Calling VB sub from JqueryDialog

本文关键字:VB 调用 JqueryDialog      更新时间:2023-09-26

所以我有一个表单,这个表单的一部分将用于创建一个jquery对话框。从该对话框是一个按钮,从asp服务器控件创建,我将单击。服务器控件在后面的代码中有一个函数,当单击该函数时将调用该函数。我遇到的问题是,代码后面的函数没有被调用。我是不是漏掉了什么基本的东西?下面是aspx页面的样子,简化到最小的

<head>
<script>        
     function PreviewForm() {              
            $("#emailPreview").attr("style", "");
            $("#emailPreview").dialog({
                title: "Preview",
                width: "890px",
                modal: true
            });
        }               
</script>
</head>
<body>
<form id="EmailSend" method="post" runat="server">  
    <table>
        <tr>
            <td style="text-align:right">                                                   
                <input type="button" onclick="PreviewForm();" value="Preview" />                                                   
            </td>
        </tr>
    </table>    
    <div id="emailPreview" align="center" style="display:none">
        <fieldset>
           <table>
                <tr class="Row">
                    <td class="required">Subject:</td>
                    <td><asp:Label ID="lblSubj" Runat="server" /></td>
                </tr>
                <tr>
                    <td class="field" colspan="2" style="text-align:center">                       
                       <input id="btnBack" class="button" type="button" onclick="closeDialog(false);" value="Close" />&nbsp;                           
                       <asp:Button ID="Send" class="button" Runat="server" Text="Send"/>
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>              
</form>        

后面代码中的函数
Private Sub CmdSendClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles Send.Click
    lblSubj.Text.Trim(), pBody)
End Sub

当我试着调试代码时,事情没有发生,断点没有被击中。如果我让这个按钮可见,并在我创建的对话框外面点击,那么它会工作得很好。

编辑

我也试过在对话框外面隐藏按钮,然后在对话框关闭后单击按钮。那么closeDialog函数将看起来像这样,并添加一个新的输入按钮

function closeDialog(send) {
    console.log(send);
       if (send) {
           $("#emailPreview").dialog("close");
           GetFormControl('<%=Send.ClientID%>').click();  
           console.log(send + " TRUE");
        } else {
            $("#emailPreview").dialog("close");
            console.log(send + " false");
        }                
 }

<div id="emailPreview" align="center" style="display:none">
        <fieldset>
           <table>
                <tr class="Row">
                    <td class="required">Subject:</td>
                    <td><asp:Label ID="lblSubj" Runat="server" /></td>
                </tr>
                <tr>
                    <td class="field" colspan="2" style="text-align:center">                                 
             <input id="btnBack" class="button" type="button" onclick="closeDialog(false);" value="Close" />&nbsp;
             <input type="button" onclick="closeDialog(true);" value="Send Email" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </div> 
        <asp:Button ID="Send" class="button" Runat="server" Text="Send"/>             
</form>        

我实际上得到了错误

SCRIPT5007: Unable to get property 'click' of undefined or null reference

编辑2

按照要求,我也知道使用eval,它的no no,但我在这里维护一些其他人的代码。假设它是ok

 function GetFormControl(fControlName) {
            var oControl = eval('document.EmailSend.' + fControlName);
            if (oControl == null)
                oControl = GetPageElement(fControlName);
            return oControl;
        }

问题是jQuery UI Dialog函数将对话框的HTML附加在表单元素之外。参见以下问题的解决方案:jQuery UI Dialog with ASP。. NET按钮回发

答:变化

$("#emailPreview").dialog({
    title: "Preview",
    width: "890px",
    modal: true
});

var diag = $("#emailPreview").dialog({
    title: "Preview",
    width: "890px",
    modal: true
});
diag.parent().appendTo(jQuery("form:first"));