开发者

Runtime ASP.NET confirmation dialog box

I need to ask the user if he/she wants to continue an operation (say, save operation).

So, after the user clicks the Save button, some stuff is 开发者_运维百科checked on the server side. If one condition is met, the user must be asked if he/she wants to proceed.

Based on user's answer, the postback should be automatically performed carrying the user's reponse back to the server, so the server will now ask again. Is it possible to do it?

Thanks.

EDIT:

To be more specific, I want this:

  1. The user clicks Save button. The postback is performed

  2. I need to make some validations/checks on SERVER SIDE (this is important!)

  3. In the middle of the postback I want to stop if a certain condition is met and ask the user if he/she really wants to continue.

  4. If the user clicks Yes, I need to re-post the request, but now I need to carry the user's response.

  5. If that "certain condition" is met again, I will just ignore it because the user wanted that.

So the solution to add the confirmation dialog right when the button is pressed is not an option because the checks are not simple and require some complex stuff involved (impossible to do it on client side).

Ajax/JS/Telerik, all OK.


You can use

btnExample.Attributes.Add("onclick", "javascript:return confirm('continue?')";

just one of the options...

EDIT:

for your needs you will want to use AJAX, call a method on the server and upon callback open the confirm window.

2nd Edit:

if the server side work isn't long I would this using AJAX. AJAX works asynchronously and you want a synchronous procedure, right?

instead of posting back, call an AJAX method from the javascript, which will look something like this:

Service.ProccessRequest(data, OnSucceedJSFunction, OnFailJSFunction);

this way when the server side method finishes the OnSucceedJSFunction on the JS will be called. in this function you can do something like

if (confirm('are you sure?'))
{
call another server method...
}

if you need to resend the data to the same server side method or to another server side method you can do this again and call a different OnSucceed js function.

Im not sure though about what you want to happen at the end of all the procedure...


Quick and dirty is to use javascript confirm function, tons of example on how to avoid the postback when user clicks cancel or ok.

if you need better ui control surely you can use javascript / jquery or whatever to show a nice dialog box and prevent the postback to happen or invoke it.


If non-JS users do not bother you then something like jQuery or AjaxControlToolkit could provide a modal popup solution.

If you are conscious or perhaps work for a company that needs to provide non-JS solutions then you could consider sending the user to another page asking for confirmation, you could carry any relevant info in either the Session or the Query String.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜