Click here to Skip to main content
Rate this: bad
good
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">
   <Columns>
       <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">
           <ItemTemplate>
            <asp:ImageButton ID="imgEdit" ImageUrl="~/Images/edit.jpg" ToolTip="Edit Record"                  CommandName="Edit" runat="server" />
           </ItemTemplate>
       </asp:TemplateField>
       <asp:TemplateField HeaderText="Delete">
         <ItemTemplate>
         <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?");' />
          </ItemTemplate>
       </asp:TemplateField>
    </Columns>
</asp:GridView>
 

 

 

 

 

 

 

 
Posted 28-Mar-13 2:02am
Comments
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
   
No

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 309
2 BillWoodruff 174
3 /\jmot 160
4 Suraj Sahoo | Coding Passion 160
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
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