Domanda

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>
È stato utile?

Soluzione

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 %>');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top