Add foreground scripts in C #

Source: Internet
Author: User

During WEB development, some javascript scripts are often required to complete some specific functions. How can I use C # To write code to implement this function? This problem has plagued Raytheon for many days. After reading a lot of information, I found a solution. Below is a short piece of code of a system I am currently working on, which is written for your reference.

Add the following code to the Page_load function:

Private void Page_Load (object sender, System. EventArgs e)
{
File: // useTo define the required client script. ** note the format **

String script = "<script language = javascript>" +
"Function select_unit (element)" +
"{" +
"Var arr = window. open (../Components/UnitListBox. aspx? Element = + element, left = 200, width = 300, top = 200, height = 230, status = no, toolbar = no, menubar = no, location = no, scrollbars = no); "+
"}" +
"Function select_date (element)" +
"{" +
"Var arr = window. open (../Components/SelectDate. aspx? Element = + element, left = 200, width = 300, top = 200, height = 230, status = no, toolbar = no, menubar = no, location = no, scrollbars = no); "+
"}" +
"Function show_help ()" +
"{" +
"Var arr = window. open (.. /help/WebPrintHelp. aspx, left = 100, width = 600, top = 100, height = 300, status = no, toolbar = no, menubar = no, location = no, scrollbars = yes ); "+
"}" +
"</Script> ";
If (! Page. IsClientScriptBlockRegistered ("clientScript "))File: // ThisIs the key to determining whether there is a ClientScript
This. RegisterClientScriptBlock ("clientScript", script );File: // ThisIs the key. If not, write the script.
File: // tryTest successful
This. ImageButton1.Attributes. Add ("onclick", "javascript: select_unit(UserDetail.txt Unit )");
This. ImageButton2.Attributes. Add ("onclick", "javascript: show_help ()");

File: // ......His functions are written here
}

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.