Groups | Blog | Home
all groups > asp.net building controls > july 2004 >

asp.net building controls : Alerting the user from code behind


Peter Aitken
7/31/2004 1:53:16 PM
I need to alert the user when code behind in a user control encounters
certain data conditions. I'd like to do this with a MsgBox but I know that
code behind cannot call this function, at least not directly. Is there a way
to do this?

--
Peter Aitken

Remove the crap from my email address before using.

Peter Aitken
7/31/2004 7:10:13 PM
[quoted text, click to view]

To answer my own question

Response.write("<script>alert("The message")</script">)


--
Peter Aitken

Remove the crap from my email address before using.

Adam Kinney
8/1/2004 11:33:44 PM
I would suggest using a Register method of the Page Class instead. You gain
more control of where the javascript is added to the page and you ensure the
javascript is only added once.

RegisterStartupScript -
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassRegisterStartupScriptTopic.asp

RegisterClientScriptBlock -
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassRegisterClientScriptBlockTopic.asp?frame=true


Adam Kinney
http://www.adamkinney.com


[quoted text, click to view]

Peter Aitken
8/2/2004 8:48:23 AM
[quoted text, click to view]


Thanks, Adam. When would you use the Client version versus the Startup
version?

--
Peter Aitken

Remove the crap from my email address before using.

AddThis Social Bookmark Button