I’m trying to access server control that locate inside GridView, but I dont have idea how to do that..
Here is my try:
<asp:GridView ....
.....
<Columns>
<asp:TemplateField>
...
..
<EditItemTemplate>
<asp:TextBox ID="txtName"runat="server" Text='<%# Bind("Name") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="edit" ItemStyle-CssClass="td"
HeaderStyle-CssClass="listtitle">
<ItemTemplate>
<asp:ImageButton ID="btnEdit" runat="server" CommandName="Edit"
AlternateText="edit" ImageUrl="~/css/images/edit-icon.png" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" runat="server" CommandName="Update" Text="Save"
OnClientClick="javascript:return isValid('<%= txtName.ClientID%>')" /> |
<asp:LinkButton ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
...
..
</Columns>
.....
....
</asp:GridView>
The problem is in here
OnClientClick="javascript:return isValid('<%= txtName.ClientID%>')"
When it gets to the isValid function I see the string “<%= txtName.ClientID%>” and not the actual controller id as I should..
So the question is how can I send the id to the JS script?
ibrams answer would have been correct if it was the fields are on
ItemTemplate. But this won’t work when you are onEditItemTemplateone have to check theRowStatealso. The condition will be something like thisBut a shorter solution will be checking this condition
GridView1.EditIndex == e.Row.RowIndexThe snippet should be this.