简体   繁体   English

如何在JavaScript上执行存储过程Confirmbutton在ASP.NET中单击

[英]How to Execute the Stored Procedure on Javascript Confirmbutton Click in ASP.NET

I have a .aspx page which has a button "clickme" on which I want to execute a storedprocedure after JavaScript Confirm button is clicked. 我有一个.aspx页面,该页面上有一个按钮“ clickme”,单击JavaScript确认按钮后,我要在该按钮上执行存储过程。 if user clicks "Yes" then only execute Storedprocedure if "Cancel" pressed do not execute the stored procedure...the button is server control. 如果用户单击“是”,则仅在按下“取消”时不执行存储过程,才执行存储过程...该按钮是服务器控件。

Help Appreciated! 帮助赞赏!

In your Page_Load event, put the following code (or you could put the equivalent code in the aspx page). 在您的Page_Load事件中,输入以下代码(或者您可以在aspx页面中输入等效的代码)。

btnSubmitRequest.Attributes.Add("onclick", "return window.confirm('Submit Request?');");

Where btnSubmitRequest is the ID you gave the button on the aspx page and Submit Request is the message you want to display to the user (you must put the message in single quotes). 其中btnSubmitRequest是您在aspx页面上为按钮提供的ID, Submit Request是要向用户显示的消息(必须将消息放在单引号中)。 The button must also be created with runat="server" tag. 还必须使用runat =“ server”标记创建按钮。

If the user clicks OK on the JavaScript window, the OnClick event for the button will fire. 如果用户在JavaScript窗口上单击“确定”,则将触发该按钮的OnClick事件。 You can call the stored procedure in there. 您可以在其中调用存储过程。 If the user clicks Cancel on the JavaScript window, the OnClick event will never fire. 如果用户在JavaScript窗口上单击“取消”,则永远不会触发OnClick事件。

If you make the button runat=server you can still catch the click event in javascript and do your javascript. 如果将按钮设置为runat = server,您仍然可以在javascript中捕获click事件并执行javascript。 Simply return true from your javascript if you want it to continue to process the postback normally or false if you want to cancel the postback. 如果您希望它继续正常处理回发,只需从javascript返回true;如果要取消回发,则返回false。

How about this: 这个怎么样:

On JavaScript function click you can do an ajax post to a static web Method and in that method you call perform operations. 在JavaScript函数上,单击可以将ajax发布到静态web方法,然后在该方法中调用执行操作。 Check the below link 检查以下链接

http://www.aspsnippets.com/Articles/Make-AJAX-Call-to-ASP.Net-Server-Side-Web-service-method-using-jQuery.aspx http://www.aspsnippets.com/Articles/Make-AJAX-Call-to-ASP.Net-Server-Side-Web-service-method-using-jQuery.aspx

Note: Use OnClientClick if button is server control.. 注意:如果按钮是服务器控件,请使用OnClientClick。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM