开发者

JavaScript Yes/No Preceding ASP.NET Button Event

Hi I'm trying to learn more JavaScript AJAX. Basically I would like to have a popup Yes No on a delete button that would precede th开发者_运维知识库e actual C# event being fired. I could do this all in C# but I know doing it client side would be beneficial as it would reduce server load.

I'm not sure exactly how to go about this. Any ideas?


You can use the javascript function called confirm

onclick="return confirm ('Are you sure you want to delete this _____?');"

This text parameter is the text that will be shown in the modal with the yes and no.

The Yes returns true which allows the postback to continue, but the No returns false and will stop the postback.

EDIT:

As mentioned by XaiSoft and Cybernate, if you are using an ASP.NET button you can also use the OnClientClick property which will be translated to onclick by the server.


You can use OnClientClick property of the asp:Button.. along with the JS confirm.. Try something like the code below in your aspx/ascx/master:

<asp:Button id="cmdSubmit" OnClientClick="return confirm('Are you sure?')" runat="server" .../>


You can also use jQuery instead of the ugly default confirm. Here is a question addressing that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜