Reputation: 2780
I have developed an asp.net custom control using text box, and its used in different places in a form, how can i get the text box value from different custom control.
I am using following syntax but its not working.
following propetly added to custom control class -
public TextBox ObjTextBox
{
get { return objTextBox; }
}
following code using to get custom control value
<script type="text/javascript">
function met1() {
var objTextBox = document.getElementById('<%=MyTextBox1.ObjTextBox.ClientID %>');
alert(objTextBox.value);
}
</script>
Upvotes: 0
Views: 1093
Reputation: 50728
Add a property on your custom control as:
public string TextBoxClientID
{
get
{
return objTextBox.ClientID;
}
}
And use this property as:
var objTextBox = document.getElementById('<%=MyTextBox1.TextBoxClientID %>');
Upvotes: 1