Message Box in ASP

R

Randy

Hello,
I'm trying to figure out how to set up and call a javascript pop up window
within C# ASP. I know how to use RegisterStartupScript. This works fine if I
use it in the Page_Load area. What I want to do is call a pop-up window from
several areas in my class.
For example, I've got a Submit button but based on several conditions I
might want to pop up a message with the message varying. If I put the
RegisterStartupScript in this Submit_Click function, it doesn't pop up
anything.
I'm thinking I need to register a javascript popup function and then call
the function where I need to, but I don't know how to do this.
Can someone point me in the right direction?

Thanks
 
P

Phillip Ian

It is similar to RegisterStartupScript...

Page.RegisterClientScriptBlock("alertblock", "<script
language='javascript'>function doalert() {alert('Hi there!'); return
true;}</script>")

And to call it from one of your buttons, add this:

Button1.Attributes.Add("onclick", "javascript:return doalert();")

Note that the return value will determine whether or not your page
posts back. So if you put return false in the function, you won't get
a postback, but return true will let the button continue on with
whatever server-side functionality it has.
 
R

Randy

What if you want to call it from within a button click function, and put
different messages in it based on certain processing?
How would you call it like this?
 

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

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top