Common Methods of ASP. NET JS

Source: Internet
Author: User

 

When writing ASP. NET programs, some JS scripts similar to alert are often used. You can write a class of common methods in a set for future use.

 

Using system. Web;
/// <Summary>
/// Common Javascript methods
/// </Summary>
Public class JS
{
Private Static string scriptstart = "<SCRIPT type = \" text/JavaScript \ "> ";
Private Static string scriptend = "</SCRIPT> ";

 

/// <Summary>
/// Write the JS script content
/// </Summary>
/// <Param name = "scriptstring"> script content </param>
/// <Param name = "isresponseend"> whether to interrupt server script execution </param>
Public static void writescript (string scriptstring, bool isresponseend)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. Current. response. Write (scriptstring );
Httpcontext. Current. response. Write (scriptend );
If (isresponseend)
{
Httpcontext. Current. response. End ();
}
}

/// <Summary>
/// A warning box is displayed.
/// </Summary>
/// <Param name = "alertmessage"> message </param>
/// <Param name = "isresponseend"> whether to interrupt server script execution </param>
Public static void alert (string alertmessage, bool isresponseend)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. Current. response. Write ("alert ('" + alertmessage + "'); history. Back ();");
Httpcontext. Current. response. Write (scriptend );
If (isresponseend)
{
Httpcontext. Current. response. End ();
}
}

/// <Summary>
/// Pop up the warning box and jump
/// </Summary>
/// <Param name = "alertmessage"> message </param>
/// <Param name = "redirectpath"> jump path </param>
/// <Param name = "istopwindow"> whether to jump to full screen </param>
Public static void alert (string alertmessage, string redirectpath, bool istopwindow)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. Current. response. Write ("alert ('" + alertmessage + "');");
If (istopwindow)
{
Httpcontext. Current. response. Write ("parent. Top. Location. href = '" + redirectpath + "';");
}
Else
{
Httpcontext. Current. response. Write ("location. href = '" + redirectpath + "';");
}
Httpcontext. Current. response. Write (scriptend );
Httpcontext. Current. response. End ();
}

/// <Summary>
/// A warning box is displayed and the window is closed.
/// </Summary>
/// <Param name = "alertmessage"> message </param>
Public static void alertandclose (string alertmessage)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. Current. response. Write ("alert ('" + alertmessage + "'); window. Close ();");
Httpcontext. Current. response. Write (scriptend );
Httpcontext. Current. response. End ();
}

/// <Summary>
/// Full screen jump
/// </Summary>
/// <Param name = "redirectppath"> jump path </param>
Public static void topredirect (string redirectppath)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. Current. response. Write ("parent. Top. Location. href = '" + redirectppath + "';");
Httpcontext. Current. response. Write (scriptend );
Httpcontext. Current. response. End ();
}

/// <Summary>
/// Determine and jump
/// </Summary>
/// <Param name = "confirmmessage"> message </param>
/// <Param name = "yesredirectpath"> select "yes" and the jump path </param>
/// <Param name = "noredirectpath"> select "no" and the jump path </param>
/// <Param name = "isresponseend"> whether to interrupt server script execution </param>
Public static void confirmredirect (string confirmmessage, string yesredirectpath, string noredirectpath, bool isresponseend)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. current. response. write ("If (confirm ('" + confirmmessage + "') {location. href = '"+ yesredirectpath +"';} else {location. href = '"+ noredirectpath + "';}");
Httpcontext. Current. response. Write (scriptend );
If (isresponseend)
{
Httpcontext. Current. response. End ();
}
}

/// <Summary>
/// Judge and write the script code
/// </Summary>
/// <Param name = "confirmmessage"> message </param>
/// <Param name = "yesscript"> select "yes" and write the script content </param>
/// <Param name = "NoScript"> select "no" and write the script content </param>
/// <Param name = "isresponseend"> whether to interrupt server script execution </param>
Public static void confirmscript (string confirmmessage, string yesscript, string NoScript, bool isresponseend)
{
Httpcontext. Current. response. Write (scriptstart );
Httpcontext. Current. response. Write ("If (confirm ('" + confirmmessage + "') {" + yesscript + "} else {" + NoScript + "}");
Httpcontext. Current. response. Write (scriptend );
If (isresponseend)
{
Httpcontext. Current. response. End ();
}
}

}

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.