Common JS methods for. Net background pages

Source: Internet
Author: User

Public class JScript
{
/// <Summary>
/// A small JavaScript window is displayed.
/// </Summary>
/// <Param name = "JS"> window Information </param>
Public static void alert (string message)
{
# Region
String JS = @ "<script language = 'javascript '>
Alert ('"+ message +"'); </SCRIPT> ";
Httpcontext. Current. response. Write (JS );
# Endregion
}

/// <Summary>
/// The message box pops up and redirects to the new URL
/// </Summary>
/// <Param name = "message"> message content </param>
/// <Param name = "tourl"> connection address </param>
Public static void alertandredirect (string message, string tourl)
{
# Region
String JS = "<script language = JavaScript> alert ('{0}'); window. Location. Replace ('{1}') </SCRIPT> ";
Httpcontext. Current. response. Write (string. Format (JS, message, tourl ));
# Endregion
}
/// <Summary>
/// The message box is displayed and directed to the homepage of the framework.
/// </Summary>
/// <Param name = "message"> message content </param>
/// <Param name = "tourl"> connection address </param>
Public static void alerttopredirect (string message, string tourl)
{
# Region
String JS = "<script language = JavaScript> alert ('{0}'); top. Location. Replace ('{1}') </SCRIPT> ";
Httpcontext. Current. response. Write (string. Format (JS, message, tourl ));
# Endregion
}

/// <Summary>
/// Return to the history page
/// </Summary>
/// <Param name = "value">-1/1 </param>
Public static void gohistory (INT value)
{
# Region
String JS = @ "<script language = 'javascript '>
History. Go ({0 });
</SCRIPT> ";
Httpcontext. Current. response. Write (string. Format (JS, value ));
# Endregion
}

/// <Summary>
/// Close the current window
/// </Summary>
Public static void closewindow ()
{
# Region
String JS = @ "<script language = 'javascript '>
Parent. Opener = NULL; window. Close ();
</SCRIPT> ";
Httpcontext. Current. response. Write (JS );
Httpcontext. Current. response. End ();
# Endregion
}

/// <Summary>
/// Refresh the parent window
/// </Summary>
Public static void refreshparent (string URL)
{
# Region
String JS = @ "<script language = 'javascript '>
Window. opener. Location. href = '"+ URL +"'; window. Close (); </SCRIPT> ";
Httpcontext. Current. response. Write (JS );
# Endregion
}

/// <Summary>
/// Refresh to open the window
/// </Summary>
Public static void refreshopener ()
{
# Region
String JS = @ "<script language = 'javascript '>
Opener. Location. Reload ();
</SCRIPT> ";
Httpcontext. Current. response. Write (JS );
# Endregion
}

/// <Summary>
/// Open 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"> header position </param>
/// <Param name = "Left"> left position </param>
Public static void openwebformsize (string URL, int width, int heigth, int top, int left)
{
# 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 );
# Endregion
}

/// <Summary>
/// Go to the URL-based page
/// </Summary>
/// <Param name = "url"> connection address </param>
Public static void javascriptlocationhref (string URL)
{
# Region
String JS = @ "<script language = 'javascript '>
Window. Location. Replace ('{0 }');
</SCRIPT> ";
JS = string. Format (JS, URL );
Httpcontext. Current. response. Write (JS );
# Endregion
}

/// <Summary>
/// Open the mode dialog box with the specified size and position
/// </Summary>
/// <Param name = "webformurl"> connection address </param>
/// <Param name = "width"> width </param>
/// <Param name = "height"> height </param>
/// <Param name = "TOP"> distance from top </param>
/// <Param name = "Left"> left </param>
Public static void showmodaldialogwindow (string webformurl, int width, int height, int top, int left)
{
# Region
String features = "dialogwidth:" + width. tostring () + "PX"
+ "; Dialogheight:" + height. tostring () + "PX"
+ "; Dialogleft:" + left. tostring () + "PX"
+ "; Dialogtop:" + TOP. tostring () + "PX"
+ "; Center: Yes; help = no; resizable: No; Status: No; scroll = yes ";
Showmodaldialogwindow (webformurl, features );
# Endregion
}

Public static void showmodaldialogwindow (string webformurl, string features)
{
String JS = showmodaldialogjavascript (webformurl, features );
Httpcontext. Current. response. Write (JS );
}

Public static string showmodaldialogjavascript (string webformurl, string features)
{
# Region
String JS = @ "<script language = JavaScript>
Showmodaldialog ('"+ webformurl +"', '', '" + features + "'); </SCRIPT> ";
Return JS;
# Endregion
}
}

 

In addition, if there is a scriptmanager on the page, use the following method to pop up the dialog box, otherwise the style will be lost

Scriptmanager. registerclientscriptblock (this, this. GetType (), "JS", "alert ('committed successfully')", true );

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.