MessageBox.show("message goes here");
but this is not the case in web applications as there is no support for displaying a message box with a custom message directly.
So here is an alternative, we can make use of a javascript to display an alert box with the custom message.
To acheive the alert box functionality follow the steps :
1) Create a Alert.cs file in AppCode folder.
2) Copy & Paste the below code in the Alert.cs file
3) you can just call the show() from any .cs file in the project like this Alert.show("message");
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///
/// Summary description for Alert
///
public static class Alert
{
public static void show(string message)
{
string cleanMessage = message.Replace("'", "\\'");
string script = "";
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null && !page.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}
}
}
This is all about displaying custom message.
No comments:
Post a Comment