Asp.net page pop-up window call

Source: Internet
Author: User

During the development process, you need to pop up a window prompting the user that the operation is successful or failed... every page is written

Response. Write ("<SCRIPT> alert ('charity information modified successfully! '); Location. href = 'charityinfomanage. aspx' </SCRIPT> ");

Or

Page. clientscript. registerstartupscript (this. GetType (), "", "<SCRIPT Lanuage = JavaScript> alert ('') </SCRIPT> ");

It is troublesome. If you put the pop-up prompt in a class file, it will be very convenient to directly call the messbox function prompt when needed .. An error is reported when the CS file is directly called using the preceding two methods. The key is that the two methods are written in system. web. UI. page Definition. If you want to use it in other class files, you must inherit the class.

Test code:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. configuration;

/// <Summary>
/// Abstract description of MessageBox
/// </Summary>
Namespace xx
{
Public class messagebox1: system. Web. UI. Page
{
Public messagebox1 ()
{
//
// Todo: add the constructor logic here
//
}
Public void getbox (string strcontent, string strurl)
{
String script = "<SCRIPT> alert ('" + strcontent + "'); window. Location. href = '" + strurl + "'; </SCRIPT> ";
Page. clientscript. registerclientscriptblock (GetType (), "", script );
}
}
}

Other. CS methods to call this method page must inherit this

Public partial class testmessagebox: XX. messagebox1
{
Protected void page_load (Object sender, eventargs E)
{
Getbox ("error", "defaultajaxpic. aspx ");
// Response. Write ("<SCRIPT> alert ('pop-up window '); window. Location. href = 'defaultajaxpic. aspx'; </SCRIPT> ");
}
}

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.