0

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>
5
  • log error if any please. or what is alerted? Commented Jun 19, 2013 at 13:53
  • its saying floowing error - ": 'string' does not contain a definition for 'ClientID' and no extension method 'ClientID' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)" Commented Jun 19, 2013 at 13:57
  • appears that MyTextBox1.ObjTextBox is string. try this: <%=MyTextBox1.ClientID %> Commented Jun 19, 2013 at 14:00
  • just try this var objTextBox= $("#<%=ObjTextBox.ClientID %>") Commented Jun 19, 2013 at 14:26
  • MyTextBox1 is name of custom control put inside webform Commented Jun 19, 2013 at 16:09

1 Answer 1

1

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 %>');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.