In the Javascript script of the client, you must first obtain the reference of the control when you want to operate the server control. Generally, the ID of the server control on the Web page is obtained first. by calling the method of the documnet object, you can obtain the reference of the server control.
For example, a server control is defined on a webpage.
<Asp: dropdownlist id = "equipmentlist" runat = "server" width = "96px"> </ASP: dropdownlist>
In the script, you can use the VaR list = document. getelementbyid ("equipmentlist"); obtain the reference of the control, and then you can operate the control, such as list. options. length = 3; you can also use document. all ["equipmentlist"]. options. length = 3; an implementation. I have just learned how to use web development.
Problem: a user control is defined. The user control contains several server controls, and a script is written into the user control to control the server control. Still follow the above method, error. The prompt is: the document. getelementbyid ("equipmentlist") is null or not an object, indicating that the equitmentlist control is not found and no reference is obtained. After instruction, it is learned that when a user control is placed on a webpage, the ID of its internal server control will change, not the ID defined in the user control. To obtain this ID, use the following statement: <% = Server Control name. clientid %> to modify the script in the user control.Code, Replace the original ID with: <% = Server Control name. clientid %>, for example:
VaR list = Document. getelementbyid ("equipmentlist"); changed to VaR list = Document. getelementbyid ("<% = equipmentlist. clientid %>"); the Code runs successfully.