Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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
Javascript事件和函数触发器_Javascript_C# - Fatal编程技术网

Javascript事件和函数触发器

Javascript事件和函数触发器,javascript,c#,Javascript,C#,我想在服务器上触发onclick事件,并在客户端调用函数(notBrowserClose()) <asp:Button ID="ButtonSave0" runat="server" OnClick="notBrowserClose(); ButtonSave_Click" Text="Save all" Style="margin-left: 860px" Width="170px" /> 这个代码不起作用,但是你知道我想做什么 <asp:Button ID=

我想在服务器上触发onclick事件,并在客户端调用函数(notBrowserClose())

  <asp:Button ID="ButtonSave0" runat="server"  OnClick="notBrowserClose(); ButtonSave_Click"  Text="Save all" Style="margin-left: 860px" Width="170px" />

这个代码不起作用,但是你知道我想做什么


<asp:Button ID="ButtonSave0" runat="server"  OnClientClick="notBrowserClose();" OnClick="ButtonSave_Click"  Text="Save all" Style="margin-left: 860px" Width="170px" />

您应该区分
OnClick
OnClientClick
,前者用于服务器端事件处理程序,后者用于客户端JS事件处理程序:

 <asp:Button ID="ButtonSave0" runat="server" 
 OnClick="ButtonSave_Click" OnClientClick="notBrowserClose();" 
 Text="Save all" Style="margin-left: 860px" Width="170px" />

您应该区分
OnClick
OnClientClick
,前者用于服务器端事件处理程序,后者用于客户端JS事件处理程序:

 <asp:Button ID="ButtonSave0" runat="server" 
 OnClick="ButtonSave_Click" OnClientClick="notBrowserClose();" 
 Text="Save all" Style="margin-left: 860px" Width="170px" />

可能是您可以使用如下所示的方法尝试此操作:

 $('#<%=ButtonSave0.ClientID%>').click(function () {
        // your code goes here
        // if this alerts triggers your function is being called alright
        alert('i am here !');
        // is this a variable ??? may be you can declare it first ?
        browserClose = false; 
        alert("tr"); 
    });
$('#')。单击(函数(){
//你的密码在这里
//如果此警报触发,您的函数正在被调用
警惕(“我在这里!”);
//这是一个变量吗???也许你可以先声明它?
browserClose=false;
警报(“tr”);
});
Click()将事件处理程序绑定到“Click”JavaScript事件,或在元素上触发该事件。 此外,您正在使用button的客户端id,如上面的代码所示


希望这有帮助

可能是这样的,您可以使用以下方法进行尝试:

 $('#<%=ButtonSave0.ClientID%>').click(function () {
        // your code goes here
        // if this alerts triggers your function is being called alright
        alert('i am here !');
        // is this a variable ??? may be you can declare it first ?
        browserClose = false; 
        alert("tr"); 
    });
$('#')。单击(函数(){
//你的密码在这里
//如果此警报触发,您的函数正在被调用
警惕(“我在这里!”);
//这是一个变量吗???也许你可以先声明它?
browserClose=false;
警报(“tr”);
});
Click()将事件处理程序绑定到“Click”JavaScript事件,或在元素上触发该事件。 此外,您正在使用button的客户端id,如上面的代码所示


希望这有帮助

尝试下面的代码…共享您的javascript代码。尝试下面的代码…共享您的javascript代码。我以前尝试过这个,但它不起作用,函数没有被触发。@jANVI您能详细说明一下您做了哪些更改吗?添加了OnClientClick()我以前尝试过这个,但它不起作用,函数没有被触发。@jANVI你能详细说明你做了什么更改吗?添加了OnClientClick(),我已经尝试过了,但它不起作用,函数notBrowserClose(){browserClose=false;alert(“tr”);}我有一个断点,但它没有进去。@IbrahimAweidah那是
alert(“tr”)吗
通过显示消息执行?不是它,只有onbeforeunload方法被执行:函数areYouSure(){if(allowPrompt){var confMessage=“******************************************************\n\n在离开预算页之前,请检查所有内容是否已保存。\n\n************************************返回confMessage;}}}window.onbeforeunload=是否确定;因此在发出此警报后,我不会收到“tr”“警报。我试过了,但它不起作用,函数notBrowserClose(){browserClose=false;alert(“tr”);}我有一个断点,但它没有进入其中。@IbrahimAweidah是通过显示消息执行的
alert(“tr”)
,不是,仅执行onbeforeunload方法:函数areYouSure(){if(allowPrompt){var confMessage=“************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************\n\n\n\n\n离开预算页之前,请检查;return confMessage;}}}window.onbeforeunload=areYouSure;所以在这个警报之后,我没有得到“tr”警报。