PopUp a confirmation message

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
 
A

ashelley

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
 
G

Guadala Harry

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
 
E

Eliyahu Goldin

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
 
A

Al Cadalzo

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
 
A

Al Cadalzo

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
 
A

Al Cadalzo

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
 
A

ashelley

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top