I want to show a message box on the successful save of any item. I googled it and tried different solutions, but none of them worked. Here is the code I am using:
This method works fine for me:
private void alert(string message)
{
Response.Write("<script>alert('" + message + "')</script>");
}
Example:
protected void Page_Load(object sender, EventArgs e)
{
alert("Hello world!");
}
And when your page load yo will see something like this:
I'm using .NET Framework 4.5 in Firefox.
Alert message with redirect
Response.Write("<script language='javascript'>window.alert('Popup message ');window.location='webform.aspx';</script>");
Only alert message
Response.Write("<script language='javascript'>window.alert('Popup message ')</script>");
you can use clientscript. MSDN : Clientscript
String scriptText =
"alert('sdsd');";
ClientScript.RegisterOnSubmitStatement(this.GetType(),
"ConfirmSubmit", scriptText);
try this
ClientScript.RegisterStartupScript(this.GetType(), "JSScript", scriptText);
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", scriptText); //use this
I use this and it works
public void Messagebox(string xMessage)
{
Response.Write("<script>alert('" + xMessage + "')</script>");
}
And I call like this
Messagebox("je suis la!");
@freelancer If you are using ScriptManager then try this code for message..
string script = "alert(\"Hello!\");";
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
Try This Code:Successfully
Written on click Button.
ScriptManager.RegisterStartupScript(this, GetType(),"alertMessage", "alert('Record Inserted Successfully');", true);