In this period of time, when Ajax is used, the old ASP. NET Program Upgrade to the Ajax program. During the upgrade, you can find that response. Write ("<SCRIPT> alert ('data is successfully added! ') </SCRIPT> ") Code An error occurred during execution. find the solution on the Internet. Most of the solutions on the Internet are changed to scriptmanager. registerstartupscript (updatepanel1, typeof (updatepanel), "AAA", "<SCRIPT> alert ('data added successfully! ') </SCRIPT> ", true); including the solution on the p104 page in <ASP. NET Ajax> by Chen lifu.
Because we now use Ajax (2008) in Visual Studio 3.5 beta2, when I use the preceding statement for processing, the system does not run the expected script to exit the dialog box, I wonder if Ajax 3.5 has been changed. later, I tried to add scriptmanager. registerstartupscript (updatepanel1, typeof (updatepanel), "AAA", "<SCRIPT> alert ('data added successfully! ') </SCRIPT> ", true); the final true value in the script changes to scriptmanager. registerstartupscript (updatepanel1, typeof (updatepanel), "AAA", "<SCRIPT> alert ('data added successfully! ') </SCRIPT> ", false); then you can write a common message prompt class.
Public class MessageBox
{
Private httpcontext mycontext = NULL;
Public MessageBox (httpcontext currentcontext)
{
Mycontext = currentcontext;
}
/// <Summary>
/// Customize the pop-up window content
/// </Summary>
/// <Param name = "MSG"> </param>
Public void show (string MSG)
{
// Mycontext. response. Write ("<SCRIPT> alert ('" + MSG + "'); </SCRIPT> ");
Scriptmanager. registerstartupscript (system. web. UI. page) mycontext. currenthandler, typeof (system. web. UI. page), "AAA", "<SCRIPT> alert ('" + MSG + "'); </SCRIPT>", false );
}
/// <Summary>
/// Customize the pop-up window content and switch to a new page
/// </Summary>
/// <Param name = "MSG"> Custom message </param>
/// <Param name = "url"> new page to be transferred </param>
Public void show (string MSG, string URL)
{
// Mycontext. response. write ("<SCRIPT> alert ('" + MSG + "'); javascript: Location = '" + URL + "'; </SCRIPT> ");
Scriptmanager. registerstartupscript (system. web. UI. page) mycontext. currenthandler, typeof (system. web. UI. page), "AAA", "<SCRIPT> alert ('" + MSG + "'); javascript: Location = '" + URL + "'; </SCRIPT> ", false );
}
/// <Summary>
/// Customize the pop-up window content to determine whether to close the current page
/// </Summary>
/// <Param name = "MSG"> </param>
/// <Param name = "close"> </param>
Public void show (string MSG, bool close)
{
If (close)
{
// Mycontext. response. Write ("<SCRIPT> alert ('" + MSG + "'); javascript: window. Close (); </SCRIPT> ");
Scriptmanager. registerstartupscript (system. web. UI. page) mycontext. currenthandler, typeof (system. web. UI. page), "AAA", "<SCRIPT> alert ('" + MSG + "'); javascript: window. close (); </SCRIPT> ", false );
}
Else
{
// Mycontext. response. Write ("<SCRIPT> alert ('" + MSG + "'); </SCRIPT> ");
Scriptmanager. registerstartupscript (system. web. UI. page) mycontext. currenthandler, typeof (system. web. UI. page), "AAA", "<SCRIPT> alert ('" + MSG + "'); javascript: window. close (); </SCRIPT> ", false );
}
}
}