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> ");
}
}