Click here to Skip to main content
11,479,486 members (46,978 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET
Can anyone solve this. Click event of Image button inside gridview is not firing for first time. But firing for second time. Below is my code. Thanks in advance.

 protected void Page_Load(object sender, EventArgs e)
   // some code //
 protected void Page_PreRenderComplete(object sender, EventArgs e)
   // some code //
 protected void grid1_RowCommand(object sender, GridViewCommandEventArgs e)
    if (e.CommandName == "Edit")
      // some code //
 protected void grid1_RowEditing(object sender, GridViewEditEventArgs e)
Design :
<asp:GridView ID="grid1" runat="server" AllowSorting="True" CssClass="GridStyle"                                                                              AutoGenerateColumns="False" OnRowCommand="grid1_RowCommand" DataKeyNames="ID" OnRowEditing="grid1_RowEditing" OnRowDeleting="grid1_RowDeleting">
       <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" Visible="false" />                    
       <asp:BoundField DataField="FirstName" HeaderText="First Name" ReadOnly="True" />
       <asp:BoundField DataField="LastName" HeaderText="Last Name" ReadOnly="True"  />
       <asp:TemplateField HeaderText="Edit">
            <asp:ImageButton ID="imgEdit" ImageUrl="~/Images/edit.jpg" ToolTip="Edit Record"                  CommandName="Edit" runat="server" />
       <asp:TemplateField HeaderText="Delete">
         <asp:ImageButton ID="imgDelete" ImageUrl="~/Images/Delete.gif" ToolTip="Delete Record" CommandName="Delete" runat="server" OnClientClick='return confirm("Are you sure you want to delete this item?");' />







Posted 28-Mar-13 2:02am
Member 8112455 at 28-Mar-13 7:57am
Have you used any validation controls like required field validator in your page?
navinKNR at 28-Mar-13 10:03am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 255
1 Sergey Alexandrovich Kryukov 215
2 F-ES Sitecore 175
3 Richard MacCutchan 120
4 Frankie-C 104
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,441
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100