views:

755

answers:

3

Currently I'm working on gridview it's have textbox on submit click I want to get textbox id of gridview but I an unable to find it button submit. Could anybody help me get the id?

A: 

You can get real control's id with ClientID property and use OnClientClick for button which you can create during data binding.

Simple example:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/cal.gif" />

protected void Page_Load(object sender, EventArgs e)
{
     ImageButton1.OnClientClick = "openCalendar(" + TextBox1.ClientID + ", " + X.ToString() + ", " + Y.ToString() + ");return false;";
}
sashaeve
but i want to get this id through javascript code not in c# page
Manoj Wadhwani
Use ClientId property in your JavaScript code.
sashaeve
A: 

Just use following example

<script type="text/javascript">
    var txtNameID = '<%= txtUsername.ClientID %>';
</script>
Nasser Hadjloo
A: 

I'm not sure what ID you really want to find, where the textbox/submit button is located(in gridview?) and why you need client script(perhaps there is a better way). Please supply some code.

You can get the javascript objects with DOM f.e. with nextSibling. So you even dont need an ID.

Tim Schmelter