PopUp a confirmation message

  • Thread starter Thread starter Al Cadalzo
  • Start date Start date
A

Al Cadalzo

I want to respond to a submit button click on a form by writing to a
database then display a popup confirmation window that just has a 'Success'
message and an OK button on it that returns the user to the form.

I've been playing with the RegisterStartupScript method to register my
javascript that opens a modal window that has the 'success' message. I'm
creating the <script language=javascript> block just fine. It contains a
function ShowConfirm(). How do I dynamically set the OnLoad attribute of
the <body> element to "javascript: ShowConfirm()" so that the confirmation
window displays after I do my processing in the OnClick event handler of my
button?

I'm using this code:

DirectCast(Me.FindControl("Body"),
HtmlContainerControl).Attributes("OnLoad") = "javascript:ShowConfirm()"

Is this the best way? Any suggestions?

Thanks,
Al
 
I want to respond to a submit button click on a form by writing to a
database then display a popup confirmation window that just has a 'Success'
message and an OK button on it that returns the user to the form.

I've been playing with the RegisterStartupScript method to register my
javascript that opens a modal window that has the 'success' message. I'm
creating the <script language=javascript> block just fine. It contains a
function ShowConfirm(). How do I dynamically set the OnLoad attribute of
the <body> element to "javascript: ShowConfirm()" so that the confirmation
window displays after I do my processing in the OnClick event handler of my
button?

I'm using this code:

DirectCast(Me.FindControl("Body"),
HtmlContainerControl).Attributes("OnLoad") = "javascript:ShowConfirm()"

Is this the best way? Any suggestions?

Thanks,
Al

Just put a blank label at the bottom of your form. On success, set
the text property of the label to the script you want to run.

-Adam
 
Hi Al

Might I suggest that perhaps you are closer than you think?
RegisterStartupScript can be used all by itself to accomplish what you want.
You don't have to dynamically set the OnLoad attribute of the <body>
element. Remember that RegisterStartupScript not only can dynamically add
script to your page, but it can be used to immediately execute JavaScript
(i.e., instruct the client execute it immediately upon receipt). Try putting
the following code at the end of your server-side routine that updates your
database:

string scriptString = "<script language=JavaScript>ShowConfirm();</script>";

if(!this.IsClientScriptBlockRegistered("clientScript1")){
this.RegisterStartupScript("clientScript1", scriptString);
}

Note: I have not tested this code - rather I pulled some working code that
does something similar to what you need and modified it to include your
ShowConfirm() call. It might need to be tweaked...

-GH
 
Al,

All you need to do is to put the javascript statement in the Http response:
Page.Response.Write("<script
language=\"Javascript\">ShowConfirm()</script>");

Eliyahu
 
Eliyahu,

TFYR.

I could not get this technique to work.
When I view source I do not see this script. I step through the code so I
know that it is doing the Response.Write.

Thanks,
Al
 
Guadala,

TFYR. That worked great and it's nice because I can just create the
function in the .aspx and not in the code-behind.

Thanks,
Al
 
Thanks Adam. Your method works just fine.

Al

Just put a blank label at the bottom of your form. On success, set
the text property of the label to the script you want to run.

-Adam
 
Thanks Adam. Your method works just fine.

Al

Just as a note, you can set the property of the label and just set it
to visible when you want the javascript to run.

-Adam
 
Back
Top