简体   繁体   中英

ASP.net and Javascript confirmation

I have this situation: I have an asp page that have a form and an action button. When user click button, it must show a confirmation box (confirm) to ask user. If user say OK it must do action A, and if user say Cancel it must do action B. The problem is that A,B action is on server-side and user are on client side. Because it require 2 action so I cannot add return confirm() into onclick attribute. So I what I've done is create a hidden field in the form and write javascript function that ask user and return value in hidden field and submit form then take action on server based on hidden field.

My question is: Is there any better design for this case?

Yes, at least in my opinion, it is worth taking a look at the ajax control toolkit, in particular:

http://www.asp.net/ajaxlibrary/act_Popup.ashx

Use two buttons in the form instead of asking after the form is submitted.

<input type="submit" name="action" value="OK">
<input type="submit" name="action" value="Cancel">

Only the clicked one will be successful.

Yes Ajax is the best.

You can also do via JavaScript as well using

location.href = newPageUrl; 

mostly in redirection Scenario

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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