Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于jquery函数调用,必须单击ASP.net按钮两次_Jquery_Asp.net_Postback - Fatal编程技术网

对于jquery函数调用,必须单击ASP.net按钮两次

对于jquery函数调用,必须单击ASP.net按钮两次,jquery,asp.net,postback,Jquery,Asp.net,Postback,我需要什么:我有需要更改和更新的工作代码。我有一个模式控件(就像一个弹出框),点击按钮就会调用它。现在,我需要在vb.net代码中计算一些东西,然后决定调用它。(弹出框出现) 问题:它会被调用,但我必须单击两次按钮。仅当CssClass设置如下时才会调用:CssClass=“osx ImageButton100” 背景:我正在使用的模式控件: 所做的更改: Before: <asp:Button ID="btnCheckOut" runat="server" Text="Preview

我需要什么:我有需要更改和更新的工作代码。我有一个模式控件(就像一个弹出框),点击按钮就会调用它。现在,我需要在vb.net代码中计算一些东西,然后决定调用它。(弹出框出现)

问题:它会被调用,但我必须单击两次按钮。仅当CssClass设置如下时才会调用:
CssClass=“osx ImageButton100”

背景:我正在使用的模式控件:

所做的更改:

Before:

 <asp:Button ID="btnCheckOut" runat="server" Text="Preview Order" CssClass="osx ImageButton100"        />
之前:

在您的代码隐藏中,什么是
Utils.MessageBox
?(从按钮单击事件处理程序调用)

无论如何,在我看来,您的代码的行为符合设计要求。步骤:

  • 用户点击按钮
  • 回发发生时,服务器端代码在按钮上设置属性,将其配置为显示弹出窗口
  • 发送回客户端的页面响应
  • 用户第二次单击按钮,现在它显示一个模态(因为它的类已配置)
  • 通过发出回发(单击按钮调用服务器端事件处理程序),您正在中断客户端代码流。关于如何进行流程,有几个选项:

  • 继续使用回发,但让服务器端代码注册一个“启动”脚本,以便在javascript页面加载事件上执行。这可能有点笨拙,尤其是当用户刷新页面时
  • 让您的按钮单击执行回调而不是回发。有几种不同的方法可以做到这一点,但我建议不要使用WebForms
    UpdatePanel
    方法
  • 将所有这些逻辑移到客户端
  • 考虑到按钮单击事件处理程序的简单性,我建议使用第三个选项。因此,忘记
    btnCheckOut
    的服务器端事件处理程序吧。首先,按钮类已设置为
    osx ImageButton100
    。然后将javascript单击处理程序更改为类似以下内容:

    $("input.osx, a.osx").click(function (e) {
        e.preventDefault();     
    
        var lineCount = $("#txtApprovalNotes").val()
                            .match(/[^\n]*\n[^\n]*/gi).length;
    
        if (lineCount > 20) {
            alert("Approval notes has a limit of 20 lines.";
        } else {
            $("#osx-modal-content").modal({
                overlayId: 'osx-overlay',
                containerId: 'osx-container',
                closeHTML: '<div class="close">
       <a href="#" class="simplemodal-close" style="font-size:150%;">x</a></div>',
                minHeight:80,
                opacity:65, 
                position:['0',],
                overlayClose:true,
                onOpen:OSX.open,
                onClose:OSX.close,
                appendTo:'form'
            });
        }
    });
    
    $(“input.osx,a.osx”)。单击(函数(e){
    e、 预防默认值();
    var lineCount=$(“#txtprovalnotes”).val()
    .match(/[^\n]*\n[^\n]*/gi);
    如果(行数>20){
    警告(“批准注释限制为20行。”;
    }否则{
    $(“#osx模态内容”).modal({
    overlayId:'osx overlay',
    containerId:“osx容器”,
    关闭HTML:'
    ',
    身高:80,
    透明度:65,
    位置:['0',],
    是的,
    onOpen:OSX.open,
    onClose:OSX.close,
    附录:'form'
    });
    }
    });
    

    这不仅可以简化逻辑流程的维护,还可以减少回帖,使浏览器的响应更加灵敏。

    你能从JavaScript调用模式吗?那会容易得多。此外,我知道这是你使用的,但我建议使用twitter引导模式。它很容易集成。
    $("input.osx, a.osx").click(function (e) {
        e.preventDefault();     
    
        var lineCount = $("#txtApprovalNotes").val()
                            .match(/[^\n]*\n[^\n]*/gi).length;
    
        if (lineCount > 20) {
            alert("Approval notes has a limit of 20 lines.";
        } else {
            $("#osx-modal-content").modal({
                overlayId: 'osx-overlay',
                containerId: 'osx-container',
                closeHTML: '<div class="close">
       <a href="#" class="simplemodal-close" style="font-size:150%;">x</a></div>',
                minHeight:80,
                opacity:65, 
                position:['0',],
                overlayClose:true,
                onOpen:OSX.open,
                onClose:OSX.close,
                appendTo:'form'
            });
        }
    });