We often encounter this situation in development: Click a button to perform a service-side operation, such as: Add data, add a successful after the need to pop up a reminder box to remind customers. The code is as follows:
private void Button2_Click (object sender, System.EventArgs e)
{
String scriptstring = "<script language=javascript>";
Scriptstring + + alert (' data write succeeded. ')";
scriptstring = "</script>";
if (!this. IsStartupScriptRegistered ("Startup")
This. RegisterStartupScript ("Startup", scriptstring);
}
Further, you can jump to other pages by implementing prompts
private void Button2_Click (object sender, System.EventArgs e)
{
String scriptstring = "<script language=javascript>";
Scriptstring + + alert (' data write succeeded. ');";
Scriptstring + = "window.location= ' test.aspx ';";
scriptstring = "</script>";
if (!this. IsStartupScriptRegistered ("Startup")
This. RegisterStartupScript ("Startup", scriptstring);
}
If you place this generic function in a public class, be careful to pass the current Page as a parameter to the past
function static void ShowMessage (System.Web.UI.Page mypage, String Info)
{
string scriptstring = "<script language=javascript>";
scriptstring += alert (' +info+ ') ';
scriptstring += "</script>";
if (!mypage. IsStartupScriptRegistered ("Startup") &NBSP;&NBSP;&NBSP
mypage. RegisterStartupScript ("Startup", scriptstring);
}