Message Boxes to Browser for Code Behind

T

Troy Whitlow

I am developing a web application using aspx web forms and
would like to send message boxes to the client browser
when certain conditions and checks are performed.

*********************************************************
Example:

Try

Perform some actions

Catch ex as system.exception ' Actions failed

I would like to send the error to the screen in the form
of a messagebox on the client browser

End try

********************************************************

Additionally, I would like to be able to prompt a
messagebox to ask questions and then process based on the
response. Similar to do you want to delete all the records
selected prompt on a yes choice then delete the records on
a no choice cancel.

All of my server code is in the Code Behind pages for each
of my aspx pages. Basically all the display is in the aspx
and all the code is in the code behind.

Any help would be greatly appreciated, especially any
sample code examples. This is my first application using
aspx. I have been writing windows apps and windows
services, but the web provides for some additional
challenges.

Troy Whitlow
 
C

Curt_C [MVP]

Nope....
You can only do this by stopping all processing, sending everythign to the
client and waiting for another post-back/round-trip to the server for the
next step....
All the server processing is done before the client gets it's chance to
interact
 
S

Steve C. Orr [MVP, MCSD]

Execute a line of code like this when you want a message box to be
displayed.
(This writes out the necessary client side javascript to your HTML page to
make the alert pop up as soon as the page is sent to their browser.)

RegisterStartupScript("startupScript", "<script
language=JavaScript>alert('This is my message.');</script>");

Here's more info:
http://msdn.microsoft.com/library/d...mWebUIPageClassRegisterStartupScriptTopic.asp

Here are a couple controls you might find to be useful:
http://www.metabuilders.com/Tools/ConfirmedButtons.aspx
http://www.jttz.com/msgbox/index.htm
 
C

Curt_C [MVP]

Does this get sent prior to the rest of the serverside code processing
though? If it does that would be kewl....but I didn't think it did?

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
 
S

Steve C. Orr [MVP, MCSD]

No, normally this gets sent along to the client along with all the other
server generated HTML & script after all the serverside code processing is
complete. Although you should be able to use Response.Write to send the
javascript out immediately if this is what you want - as long as you turn
buffering off.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
 

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

Top