Wednesday, 14 May 2014

show alert message from server side

show alert message from server side:
If you want to show msg if you are posting the page to server through update panal (asynchronous postback) then you have to use this function.

//During Asynchronous Post Back in Update Panal Use ScriptManager (Inside Update Panal)
public void alertBox(string Message)
{
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Key"string.Format("alert('{0}');", Message), true);
}
 
If you want to show message in browser and want to show it through javascript (alert function)
then use this function.
 
// During synchronous normal Post Back Use ClientScript
public static void ShowMessage(string MessageText, Page MyPage)
{
MyPage.ClientScript.RegisterStartupScript(MyPage.GetType(), 
"MessageBox", "alert('" + MessageText.Replace("'", "\'") + "');", true);
}