Technical/Business Aspects in IT

ConfirmButton using AJAX / Javascript

Posted by scmay on July 18, 2008

Where shall I begin?

The AJAX ConfirmButton control webpage

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ConfirmButton/ConfirmButton.aspx

but then I realised that my controls were server side generated. The solution was to

1. Generate a ‘hidden’ client button

2. Use Javascript to call the ‘hidden’ button (http://www.velocityreviews.com/forums/t295311-how-do-i-fire-a-server-side-button-click-event-from-javascript.html)

Step 1:
In the server side page load event just add this code…

Page.GetPostBackEventReference(ImageButton1)

Step 2:-

Try calling this line ” __doPostBack(‘btnSubmit’,’OnClick’);”

call the above function “callPostBack” after u r prompt
statement.

eg:-

<script language=”javascript” type=”text/javascript”>
function myFunction()
{
var strname;
strname = prompt(“What is your name”, “”);

// if its a valid name then just call post back..
__doPostBack(‘btnSubmit’,’OnClick’);

}
</script>

3. Server side calls the Javascript  (http://www.velocityreviews.com/forums/t66809-how-to-call-java-script-function-after-executived-the-server-side-code.html)

Response.Write(“<script>alert(‘hello,world’)</script>”);

But my 2nd issue was I didn’t want a OkCancel button, only the OK button.

Found this Alerts http://weblogs.asp.net/bleroy/archive/2005/12/01/432016.aspx

but had difficulty implementing it. And finally thought that a basic Javascript would do the job afterall.

Basic Javascript Alert, Confirm, Prompt boxes

http://www.javascriptkit.com/javatutors/alert2.shtml

The redirection of page has to be javascript as well and not from the server side, or else the Window.Alert won’t be displayed at all.

http://www.experts-exchange.com/Microsoft/Development/.NET/Visual_CSharp/Q_22881602.html

You could redirect the user via javascript to get your message box visible:

Response.Write(“<script langauge=\”javascript\”>window.alert(‘Acceso no permitido’)</script>”);
Response.Write(“<script langauge=\”javascript\”>document.location.replace(‘Menu.aspx’)</script>”);

Leave a comment