Due to project requirements, I have gained some understanding about JS development in the recent period. In ASP. NET-based development, JS scripts are often required to add some client control, such as limiting input characters and date controls. Generally, this control is better on the client, and does not need to be uploaded back to the server. Summarizes some JS skills used in recent development and provides them to you:
1. How to access the server control value using JS scripts
There is a Textbox Control on the interface, whose ID is name. In JS, you can use the following script to obtain the name value var myvalue = Document. All ('name'). value;
2. How does the Server Control obtain the value of a variable in JS?
Currently, no good method has been found. I usually use the following method: Put a hidden control htmlinputhidden on the interface and set it to run as a server control, so as to match ASP in JS scripts. net code can access the value of the control. JS, assign the value to the server control: var bt = document. all ('name '). value; BT. value = 'name'; ASP. use name. net. value.
Put a <input id = "hiddenvalue" type = "hidden" value = "" runat = "server"/>
In JS, give the variable document. All ('hiddenvalue'). value = variable;
The server reads data using this. hiddenvalue. value.
3. How to traverse all textbox elements on the Interface
VaR inputlist = document. body. getelementsbytagname ("input"); For (VAR I = 0; I <inputlist. length; I ++) {If (inputlist [I]. disabled = false & (inputlist [I]. type = 'text' | inputlist [I]. type = 'Password') {inputlist [I]. value = "";}}
4. Set dropdownlist to a specified item.
The value of "I have to select" in the dropdownlist is Var handl = document. all ('list1'); var my_value = 'I have to select'; For (VAR Index = 0; index
========================================================== ========================================================== =
How Javascript
Call C #Process in background code and ASP. NET
Call14:33:39 Source: csdn blog Author: fanweiwei 【
Large Medium Small]
Comments: 0++:
1. Background method:
Protected string csharpvoid (string strcc)
{
Return strcc;
}
2. JavascriptCall
<Script language = "JavaScript">
VaR S = "<% = csharpvoid ("Www.esoutong.com ") %> ";
Document. Write (s );
</SCRIPT>
++:
1. Post code:
Protected void csharpvoid ()
{
String strcc ="Www.esoutong.com";
Response. Write (strcc );
}
2.CallMethod: csharpvoid ()
<Script language = "JavaScript">
Document. Write ("<% csharpvoid (); %> ");
</SCRIPT>
You can place a button on the page and set it to invisible style = "display: none". Then, use a script to make this button click
Document. All ("button1"). Click ();
ClickC #Write in the backgroundEventCode. This is the simplest script.CallC #Method.
On the Internet, I saw a problem: the platform used by the author is. net.C #Developed on the local machine, in the aspx fileCall JSFile:
<Script language = "JavaScript" src = "mymenu.JS"> </SCRIPT>
The results are garbled characters on the page and alert prompts. The result is followed by a long string of solutions. In fact, it is very simple to add a line of code in the header of the aspx file:
<% @ Page contenttype = "text/html" responseencoding = "gb2312" %>
========================================================== ========================================================== =