Reputation: 237
I have a User control ascx file with a textbox in it
<asp:TextBox ID="textboxDate" runat="server" CssClass="FieldValue" MaxLength="10"
Columns="12" autocomplete="off" Style="padding-right: 18px; border: 1px solid #567890;" />
<ajaxToolkit:CalendarExtender ID="calendarExtenderDate" runat="server" TargetControlID="textboxDate"
PopupButtonID="textboxDate" />
I'm adding this user control in my aspx page
<uc:DateControl ID="dateControlStart" runat="server" RequiredErrorMessage="please enter date" />
and i want the value of this textbox . How can i do this using javascript or Jquery.
Upvotes: 0
Views: 6596
Reputation: 2653
Try the below
$("input[id*=textboxDate]").val();
Thanks
Upvotes: 3
Reputation: 17617
Since .NET creates it's own id's for controllers it's a bit problematic. But there's 2 ways around this.
1, create a containing div with an id
.
// HTML
<div id="date-container">
//.. .NET controllers
</div>
// Script
var container = document.getElementById('date-container'),
input = container.getElementsByTagName('input')[0];
console.log(input.value);
2, Add and unique css class to you asp:textbox and use jQuery to retrive it:
$('.date-input-unique').val();
Upvotes: 0
Reputation: 22619
Try to have a public property in the user control to access the text box.
Example:
In User Control code behind
public TextBox MyTextBox{
get{return this.textboxDate;}
}
In Page code behind
dateControlStart.MyTextBox.Text
Upvotes: 0