JS gets the server controls in the. aspx page and the server control values in. ascx-Practical tips

Source: Internet
Author: User
A.aspx page
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "A.aspx.cs" inherits= "Ordermanage_a"%>
<%@ Register src= ". /usercontrol/ctrlcalendar.ascx "Tagname=" Ctrlcalendar "tagprefix=" uc1 "%>"
<script language= "javascript" type= "Text/javascript" >
function GetValue ()
var Txpro=document.getelementbyid (' <%=txtprovider_rename. ClientID%> ');
When you get the value of a server control with JS, you first get the ClientID of the server control
var Txdat=document.getelementbyid (' <%=txtcheckin.clientid%> ' + "_txtdateval");
Using JS to get the server control values in the. ascx control, first get the server control's ClientID plus the server space ID inside the. ascx page and connect with "_"
<form id= "Form1" runat= "Server" >
&LT;TD align= "Right" bgcolor= "#dee5fa" > Check-in dates </td>
&LT;TD align= "left" bgcolor= "#dee5fa" ><uc1:ctrlcalendar id= "Txtcheckin" runat= "Server"/></td>
&LT;TD align= "Right" bgcolor= "#dee5fa" onclick= "GetValue ()" ><asp:textbox id= "Txtprovider_rename" runat= " Server "Width=" 312px ></asp:TextBox></td>

Copy Code code as follows:

<%@ control language= "C #" autoeventwireup= "true" codefile= " CtrlCalendar.ascx.cs "inherits=" Ctrlcalendar%>
<table id= "Table1" style= "height:24px" cellspacing= "0" cellpadding= "0" width= "border=" 0 ">
<td style=" width:81px "><font face=" Arial "> Br><asp:textbox id= "Txtdateval" width= "84px" runat= "Server" borderstyle= "Groove" ></asp:textbox></ font></td>
<td><div id= "Div_imgcanlendar" ><font face= "song Body" ></font></div></td>
</table> br>

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.