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
}