Friday, February 15, 2008

Broken Capilary Urethra

Issue an alert following a postback

Programming web applications we often find ourselves in a position of wanting to communicate something to the user in a clear manner, drawing attention to a particular condition, or an error.

on Windows Forms Using messagebox the classic, comfortable, full of options and very practical.

ASP.NET pages instead we issue the javascript code to display an js alert with the message of the case.

then I wrote a handy function in the web pages that is very similar to the following: public void
 
MessageBoxScriptInject (string messageToShow)

{/ / I give him comatose with javascript ... String =
messageTranslated
messageToShow.Replace ("'", "\\ \\ '");
messareTranslated
messareTranslated.Replace = ("\\ n", "");
messareTranslated
messareTranslated.Replace = ("\\ r", "");

/ / Create the javascript

System.Text.StringBuilder js = new System.Text.StringBuilder ();
js.AppendLine (
window.alert ('"+
messareTranslated +"'); ");

/ / injected code in the page (syntax. NET 2.0)
this.ClientScript.RegisterStartupScript (
typeof (string),
Guid.NewGuid (). ToString (),
js.ToString (),
true);}

0 comments:

Post a Comment