Solution to error in Javascript script output using response. Write in Ajax

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

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.