PDA

View Full Version : Alert boxes using ASP?


yapjiwen
01-19-2004, 05:27 PM
Is it possible to generate Alert Boxes using ASP? If so how?

Roy Sinclair
01-19-2004, 06:09 PM
Alert to who?

On the server, the answer is no. If you want to "alert" the client then you can have the ASP code write some client side script for an alert but you must understand that anything done on the client side is done after the script on the server has finished executing, you can't interact with the user partway through the server side code and use the results of that interaction later in the same code.

yapjiwen
01-20-2004, 03:12 AM
Thanks for your post.

erm...actually i wanna llike if the user forgot to fill in a certain textfield, then i alert him with an alert box.is it possible?

whammy
01-20-2004, 03:31 AM
I originally posted a pretty long tutorial in response to this thread regarding the differences between client-side and server-side scripting - but you'd be better off just posting your HTML, (assuming it's not HUGE) and we can show you the difference.

Roy's right - an "alert" is javascript - which is client-side scripting. That means that anything processed on the server has already been sent to the client (in other words, the user's browser).

There's a huge difference between validating server-side and validating client-side, one which you MUST understand, no matter what server-side language you might be using. :)

I'd check this out for starters, as a client-side reference, and then learn how to validate data redundantly (i.e. client-side first, and then server-side!). Validating data client-side can cut down on your server's bandwidth, but there is no substitute for validation on the server-side!:

http://hotwired.lycos.com/webmonkey/reference/javascript_code_library/forms_data/?tw=reference

Bullschmidt
02-05-2004, 09:27 AM
Is it possible to generate Alert Boxes using ASP? If so how?

Perhaps try something like this "Yet to be developed" JavaScript alert box:
Response.Write "<script type='text/javascript'>alert('Yet to be developed.');</script>"

Or using a variable:
MyVariable = "Yet to be developed."
Response.Write "<script type='text/javascript'>alert('" & MyVariable & "');</script>"

Or with multiple lines:
Response.Write "<script type='text/javascript'>alert('Coming soon.\nYet to be developed.');</script>"

whammy
02-12-2004, 07:54 PM
That'll work. :)

Morgoth
02-13-2004, 04:13 AM
Originally posted by whammy
That'll work. :)
Yes... That will work...

yapjiwen
02-16-2004, 09:13 AM
Thanks pple~! :thumbsup:

Bullschmidt
02-16-2004, 01:58 PM
You're welcome!

Starlight
03-03-2004, 09:09 PM
Have a look at the following articles these should help you alot. No you cannot do this in ASP.NET since since this is a client-side task and that requires javascript already mentioned. However, the good news is that you can tell APS.NET to emit javascript to the client!

Most ASP.NET server controls have an attributes.add method which allows you to add custom attribs. to the server controls such as adding a client onclick event to a asp button for invoking a confirm box or an alert box. You would place the code in your Page Load subroutine. Something like this for a button server control for invoking the alert pop up box.

yourbutton.Attributes.Add("onclick", "alert('You clicked me!')")

Article on message boxes in ASP.NET.

http://aspnet.4guysfromrolla.com/articles/021104-1.aspx
http://aspnet.4guysfromrolla.com/articles/021104-1.2.aspx

Article on pop windows with AP.NET.
http://www.riderdesign.com/articles/displayarticle.aspx?articleid=13

Adding functionality to server controls.
http://aspnet.4guysfromrolla.com/articles/100103-1.aspx

Also this article by Scott Mitchell one of the gurus on ASP.NET.
http://msdn.microsoft.com/asp.net/using/understanding/aspnet/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-injectclientsidesc.asp