Several buttons inside FormTemplate

3 posts, 0 answers
  1. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 16 Nov 2011 Link to this post

    I have a grid with a formtemplate. The formtemplate has 4 buttons: Save (CommandName="Update"), Cancel (CommandName="Cancel"), GoToStart (OnClick="btnGoToStart_Click"), PrintToPdf (OnClick="btnPrintToPdf_Click"). As you can see 2 of the buttons perform a grid command, and 2 of the buttons has their own click events. After clicking the Save button or Cancel button, the grid does exactly what's expected. But, if I click on Save, and then click on GoToStart or PrintToPdf buttons, they do not enter theis events, but acts like the Cancel button. What am I missing here?
  2. Roy Halvorsen
    Roy Halvorsen avatar
    83 posts
    Member since:
    Oct 2008

    Posted 16 Nov 2011 Link to this post

    Never mind. I found a solution. Put e.canceled = true as the last line in the UpdateCommand event.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 16 Nov 2011 Link to this post

    Hello,

    Please check below code snippet there is not such type of issue with Radgrid.
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
               OnItemCommand="RadGrid1_ItemCommand">
               <MasterTableView DataKeyNames="ID1" CommandItemDisplay="Top" EditMode="EditForms">
                   <Columns>
                       <telerik:GridBoundColumn DataField="ID1" HeaderText="ID1" UniqueName="ID1">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="ID2" HeaderText="ID2" UniqueName="ID2">
                       </telerik:GridBoundColumn>
                       <telerik:GridEditCommandColumn>
                       </telerik:GridEditCommandColumn>
                   </Columns>
                   <EditFormSettings EditFormType="Template">
                       <FormTemplate>
                           <%# Eval("ID1") %>
                           <br />
                           <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
                           <br />
                           <asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" />
                           <br />
                           <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                               runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                           </asp:Button>
                           <br />
                           <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                               CommandName="Cancel"></asp:Button>
                       </FormTemplate>
                   </EditFormSettings>
               </MasterTableView>
           </telerik:RadGrid>
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            {
                dynamic data = new[] {
                    new { ID1 = 1, ID2 = 2},
                    new { ID1 = 4, ID2 = 5}
                    
                };
                RadGrid1.DataSource = data;
     
            }
     
            protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
            {
     
            }
     
            protected void Button1_Click(object sender, EventArgs e)
            {
     
            }
     
            protected void Button2_Click(object sender, EventArgs e)
            {
     
            }
    .......................................
    If you still get the issue then give CommandName other buttons also.
    And remove click event from Button.
    Do your logic in ItemCommand event of radgrid.

    EX :

    <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" CommandName="Mycommmand1" />
    ....................
      if (e.CommandName == "Mycommmand1")
                {
                    // place your button click event here
                }


    Let me know if any concern.

    Thanks,
    Jayesh Goyani
Back to Top