Solution of error in Response.Write output JS script in Ajax

Source: Internet
Author: User
Tags httpcontext

Solution of error in Response.Write output JS script in Ajax

Ajax 3.5 is not altered. Later tried to Scriptmanager.registerstartupscript (UpdatePanel1, typeof (UpdatePanel), "AAA", "<script >alert (' Data add success! ') </script>, True); The last true in is changed to Scriptmanager.registerstartupscript (UpdatePanel1, typeof (UpdatePanel), "AAA", " <script>alert (' Data add success! ') </script> ", false); Write a generic message prompt class below.

public class MessageBox
{

Private HttpContext mycontext = null;
Public MessageBox (HttpContext currentcontext)
{
Mycontext = CurrentContext;
}
<summary>
customizing 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 pop-up window content and move to a new page
</summary>
<param name= "MSG" > Custom message </param>
<param name= "Url" > A new page to go to </param>
public void Show (String msg,string Url)
{
MyContext.Response.Write ("<script>alert (' + msg +"); Web effects: 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 pop-up window content, customize 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);
}
}
}

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.