JavaScript gets the value of the ASP. NET Server-side control

Source: Internet
Author: User
Tags control label

The code is as follows:

<%@ page language= "C #" codefile= "A.aspx.cs" inherits= "ordermanage_a"%> <%@ Register src= ". /usercontrol/ctrlcalendar.ascx "Tagname=" Ctrlcalendar "tagprefix=" uc1 "%>

Ctrlcalendar.ascx

Copy the code code as follows:

<%@ Control language= "C #" codefile= "CtrlCalendar.ascx.cs" inherits= "Ctrlcalendar"%> <table id= "Table1" style = "height:24px" cellspacing= "0" cellpadding= "0" width= "+" border= "0" > <tr> <td style= "width:81px" > <font face= "song body" > <asp:textbox id= "txtdat" width= "84px" runat= "Server" borderstyle= "Groove" ></asp: textbox></font></td> <td><div id= "Div_imgcanlendar" ><font face= "song Body" ></font></div></td> </tr> </table>

JS gets the value of the ASP. NET Server-side control Label with TextBox RadioButtonList and DropDownList when you do a BS schema project, you often encounter the need to use JS to invoke the value of the ASP. Most of the controls his value can be called by JS to call its Value property to get the values of this control, but there are exceptions. A commonly used label control. His value with JS can not be obtained by the Value property.    Label Control JS Gets an instance of Var text= document.getelementbyidx (' Label1 '). InnerText; If so, var text= document.getelementbyidx (' Label1 '). Value; The text is undefined. The value of the textbox can be var text= document.getelementbyidx (' TextBox 1 '). Value; For, RadioButtonList and DropDownList their acquisition way is very different! This is mainly because the HTML elements they generate are not the same. The value of DropDownList is simple:         var ddlvalue = document.getelementbyidx (' ctl00_ Contentplaceholder3_ddlfolws '). Value;        the value of RadioButtonList is more troublesome:         var Value = "";         var Result = document.getelementsbyname (' ctl00$contentplaceholder3$ Rblresult ');         for (var i = 0; i < result.length; i++) {             if (Result.item (i). Checked) {                 value = Result.item (i). value;            }        } If the RadioButtonList control does not have a selection then value is empty! For other controls JS gets the value of the method later in the discussion.

JavaScript Gets the value of the ASP. NET Server-side control

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.