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
2010-05-11 12:34:52
but i want to get this id through javascript code not in c# page
Manoj Wadhwani
2010-05-11 12:37:19
Use ClientId property in your JavaScript code.
sashaeve
2010-05-11 12:52:20
A:
Just use following example
<script type="text/javascript">
var txtNameID = '<%= txtUsername.ClientID %>';
</script>
Nasser Hadjloo
2010-05-11 12:50:36
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
2010-05-11 13:15:13