asp.net background How to output JS script to use what method can be implemented _ practical skills

Source: Internet
Author: User
Tags httpcontext
With page. Clientscript.registerstartupscript Way to achieve

The code is:
Copy Code code as follows:

/**////<summary>
Pop-up JavaScript small window
</summary>
<param name= "JS" > Window information </param>
public static void Alert (String message, page page)
{
#region
String js = @ "<script language= ' JavaScript ' >
Alert (' "+ Message +" ');</script> ";
HttpContext.Current.Response.Write (JS);
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "alert"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "alert", JS);
}
#endregion
}

/**////<summary>
Pop-up message box and move to the new URL
</summary>
<param name= "message" > Content </param>
<param name= "Tourl" > Connection address </param>
public static void Alertandredirect (String message, String tourl, page page)
{
#region
String js = "<script language=javascript>alert (' {0} '); Window.location.replace (' {1} ') </script>";
HttpContext.Current.Response.Write (String. Format (JS, message, tourl));
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "Alertandredirect"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Alertandredirect", String. Format (JS, message, tourl));
}
#endregion
}

/**////<summary>
Back to History page
</summary>
<param name= "Value" >-1/1</param>
public static void Gohistory (int value, page page)
{
#region
String js = @ "<script language= ' JavaScript ' >
History.go ({0});
</Script> ";
HttpContext.Current.Response.Write (String. Format (JS, value));
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "gohistory"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Gohistory", String. Format (JS, value));
}
#endregion
}

/**////<summary>
Refreshing the parent window
</summary>
public static void Refreshparent (string url, page page)
{
#region
String js = @ "<script language= ' JavaScript ' >
window.opener.location.href= ' "+ URL +" '; Window.close ();</script> ";
HttpContext.Current.Response.Write (JS);
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "refreshparent"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Refreshparent", JS);
}
#endregion
}


/**////<summary>
Refresh Open Window
</summary>
public static void Refreshopener (Page page)
{
#region
String js = @ "<script language= ' JavaScript ' >
Opener.location.reload ();
</Script> ";
HttpContext.Current.Response.Write (JS);
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "Refreshopener"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Refreshopener", JS);
}
#endregion
}


/**////<summary>
Opens a new form of the specified size
</summary>
<param name= "url" > Address </param>
<param name= "width" > Width </param>
<param name= "Heigth" > High </param>
<param name= "Top" > Head position </param>
<param name= "left" > Position </param>
public static void Openwebformsize (string url, int width, int heigth, int top, int left, page page)
{
#region
String js = @ "<script language= ' JavaScript ' >window.open (' + URL + @" ', ', ' height= ' + heigth + ", width=" + width + ") , top= "+ Top +", left= "+ Left +", location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar= No,directories=no ');</script> ";
HttpContext.Current.Response.Write (JS);
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "openwebformsize"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Openwebformsize", JS);
}
#endregion
}


/**////<summary>
Turn to URL-made page
</summary>
<param name= "url" > Connection address </param>
public static void Javascriptlocationhref (string url, page page)
{
#region
String js = @ "<script language= ' JavaScript ' >
Window.location.replace (' {0} ');
</Script> ";
JS = string. Format (JS, url);
HttpContext.Current.Response.Write (JS);
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "Javascriptlocationhref"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Javascriptlocationhref", JS);
}
#endregion
}

/**////<summary>
Opens a modal dialog box with a specified size position
</summary>
<param name= "Webformurl" > Connection address </param>
<param name= "width" > Width </param>
<param name= "height" > High </param>
<param name= "Top" > Distance position </param>
<param name= "left" > Away position </param>
public static void Showmodaldialogwindow (string webformurl, int width, int height, int top, int left, page page)
{
#region
String features = "Dialogwidth:" + width. ToString () + "px"
+ ";d ialogheight:" + height. ToString () + "px"
+ ";d ialogleft:" + left. ToString () + "px"
+ ";d ialogtop:" + top. ToString () + "px"
+ "; Center:yes;help=no;resizable:no;status:no;scroll=yes";
Showmodaldialogwindow (Webformurl, features, page);
#endregion
}

/**////<summary>
Pop-up modal window
</summary>
<param name= "Webformurl" ></param>
<param name= "Features" ></param>
public static void Showmodaldialogwindow (string Webformurl, String features, page page)
{
String js = Showmodaldialogjavascript (Webformurl, features);
HttpContext.Current.Response.Write (JS);
if (!page. Clientscript.isstartupscriptregistered (page. GetType (), "Showmodaldialogwindow"))
{
Page. Clientscript.registerstartupscript (page. GetType (), "Showmodaldialogwindow", JS);
}
}
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.