I asked this question regarding a strange behaviour from a GridView control in ASP.Net (I'm using C#).
For each row in my GridView there is an an 'Edit' and 'Delete' link. The edit for example has this javascript:__doPostBack('gvwServers','Edit$0')
- So obviously the server is going to figure out someone has clicked to edit row 0
of gvwServers
.
Fair enough. If I click the Edit link I get a postback and the GridView is redrawn with the Edit button replaced with an 'Update' and 'Cancel' button. Standard behaviour. NOW - The 'Cancel' button has this link javascript:__doPostBack('gvwServers','Cancel$0')
- just what I would expect Cancel row 0
of gvwServers
. BUT The Update button has javascript:__doPostBack('gvwServers$ctl02$ctl00','')
. This appears to not make any sense. And this appears to be the cause of my routine to handle Update not being fired.
Why is ASP not outputting the correct postback arguments?
My code is available at the link above.
<asp:GridView ID="gvwServers" runat="server" class="gvwServers"
AutoGenerateColumns="false" OnRowEditing="gvwServers_Edit"
onrowcancelingedit="gvwServers_Cancelling" onrowdeleting="gvwServers_Deleting"
onrowupdated="gvwServers_Updated" onrowupdating="gvwServers_Updating"
AutoGenerateEditButton=true AutoGenerateDeleteButton=true>
<columns>
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />
<asp:BoundField DataField="intServerID" visible="false" />
<asp:TemplateField HeaderText = "Server Name">
<ItemTemplate>
<asp:Label ID="lblServerName" runat="server" Text='<%# Bind("txtName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtServerName_Edit" runat="server" Text='<%# Bind("txtName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Key">
<ItemTemplate>
<asp:Label ID="lblAppKey" runat="server" Text='<%# Bind("txtApplicationKey") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAppKey_Edit" runat="server" Text='<%# Bind("txtApplicationKey") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Connection String">
<ItemTemplate>
<asp:Label ID="lblConnString" runat="server" Text='************'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtConnString_Edit" Width="300px" Height="100px" Text='<%# Bind("txtConnectionString")%>' TextMode="MultiLine" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
Not sure what you're expecting/not happening. I took your gridview code and used your code behind in the other link. I added a Response.Write in each handler and it seems to run as expected.