views:

95

answers:

2

Suppose I have an ASP.NET Text Box as Below :

<asp:TextBox ID="txtQuantity" runat="server" Text="0"></asp:TextBox>

I want to get this box's current value in javascript. How can I access this element? If it was a normal html text box, with id="txtQuantity", then I could access it using "document.getElementById("txtQuantity")". But how can I access ASP.NET text box in javascript?

+5  A: 

use the clientID property

document.getElementByID('<%=txtQuantity.ClientID %>')

More information here

you can also use find

Quoted from the above link:

Additionaly the ClientID is used in ASP.NET Ajax as the unique identifier of client-side controls. Thus the following JavaScript statement is commonly used:

var control = $find("<%= MyControl1.ClientID %>");

ram
Thank you Ram, I got it now
Night Shade
+2  A: 

You can get the client side ID using txtQuantity.ClientID.

Idan K