Wednesday, April 29, 2009

How to Show a Mesage Box in ASP.NET

A lot of Developer from windows Platform who are new to Web Development , tries to mimic what they were doing in Windows Development on the Web. Well it would be nice if Microsoft can add this feuture in ASp.net. Message boxes are the way a Developer interect with his or her users. In Windows Application its simple because you just need to call the Function

MessageBox.Show("Your Message here...");

This can still be used in the Web but , your message box will show at the taskbar and this will not be your intentions. To over come this in Asp.net you have to create a Function like this


public void CreateMessageAlert(System.Web.UI.Page aspxPage, string strMessage, string strKey)
{
string strScript = "";
if (!ClientScript.IsStartupScriptRegistered(strKey))
{
ClientScript.RegisterStartupScript(typeof(Page), strKey, strScript);
}
}

and you can call it like this



string strMessage = "You Message here...";
CreateMessageAlert(this.Page, strMessage, "strKey1");


That is Simple.

Vuyiswa Maseko

No comments:

Post a Comment