Implementation pops up the Reminder dialog box after executing the service-side code

Source: Internet
Author: User
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);        
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.