Reputation: 15138
I want a simple MessageBox for ASP.Net, but everything I tried didn't work and I don't know why. The last thing I tried was this but it didn't work either.
Any ideas for a simple messagebox with work safe?
For more information:
Test it with onClick on the button:
string msg = "Text";
string script = "<script language=JavaScript>alert("+msg+");</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", script);
but it doesn't work
Upvotes: 1
Views: 1141
Reputation: 8474
Here is your answer.
http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string s = "here in button event";
string script = "<script language=JavaScript>alert('" + s + "');</script>";
if (!Page.ClientScript.IsStartupScriptRegistered("clientScript"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", script);
}
}
}
Upvotes: 2
Reputation: 854
Is this using ajax? Is this attached to a server side event that's called when the user clicks a button?
If so, ajax only sends data that's associated with the updatepanel in question. If so, try this ScriptManager.RegisterStartupScript((Control)ctlControl, ctlControl.GetType(), "ClientScript", "alert('foo')", true); It is important that the ctlControl is inside the updatepanel being updated.
If you are not using ajax, is ClientScript registered elsewhere with RegisterClientScriptBlock? The client name has to be unique for every registry or it will think you are calling the same code twice.
Upvotes: 0
Reputation: 3063
You could use the dialog component from jQuery UI to display a message box. A simple usage demo is available here.
Upvotes: 3