Confirmation Box appears on clicking twice on the link button of a template column.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MassiveMohit
    New Member
    • Nov 2014
    • 3

    #1

    Confirmation Box appears on clicking twice on the link button of a template column.

    I have a DataGrid, to which I have added a template column for importing data to the data base.
    I added the confirmation logic as discussed in this forum.
    Now I have to click twice for the confirm box to appear.


    I have a data grid with the template column. Below is the code:
    Code:
    <asp:DataGrid ID="dgImportList" runat="server" Width="100%" BorderStyle="Solid" AutoGenerateColumns="False">  
      <AlternatingItemStyle CssClass="tabledata2"></AlternatingItemStyle>
      <ItemStyle CssClass="tabledata1"></ItemStyle>
      <HeaderStyle CssClass="tableHeader2"></HeaderStyle>
      <Columns>
        <asp:BoundColumn DataField="FileName" HeaderText="Name"></asp:BoundColumn>
        <asp:BoundColumn DataField="Date" HeaderText="Date"></asp:BoundColumn>
        <asp:ButtonColumn ButtonType="LinkButton"  Text="Import" CommandName="Import"></asp:ButtonColumn>
        <asp:ButtonColumn ButtonType="LinkButton" Text="Check" CommandName="FormatCheck">
        </asp:ButtonColumn>
        <asp:TemplateColumn>
        <ItemTemplate>
          <asp:LinkButton ID="lbImportTemplate"
            runat="server"
            CausesValidation="false" 
            CommandName="ImportTemplate"
            Text="ImportTemplate"
            OOnClick="ConfirmBtnClickHandler"></asp:LinkButton>
        </ItemTemplate>
      </asp:TemplateColumn>
      </Columns>                                          </asp:DataGrid>

    Also the asp.net code which asks for confirmation. Below is the code:
    Code:
    private void dgImportList_ItemCommand(Object sender, DataGridCommandEventArgs e)
            {
    
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    LinkButton lb = e.Item.FindControl("lbImportTemplate") as LinkButton;
                    lb.OnClientClick = "if(!confirm('Are you sure to import this item?')){return false;}";
                    //Do something
                }
    I have to click on the link button twice, to get the confirm box populated.

    Please help!
    Last edited by Frinavale; Nov 19 '14, 02:43 PM.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Instead of waiting until the user clicks the link, use the GridView.RowDat aBound Event to apply the client click JavaScript code that asks for confirmation.

    Or change your Template to include the Client Click code like this:

    Code:
    <asp:TemplateColumn>
        <ItemTemplate>
          <asp:LinkButton ID="lbImportTemplate"
            runat="server"
            CausesValidation="false" 
            CommandName="ImportTemplate"
            Text="ImportTemplate"
            OnClick="ConfirmBtnClickHandler"
            OnClientClick="if(!confirm('Are you sure to import this item?')){return false;}"></asp:LinkButton>
        </ItemTemplate>
      </asp:TemplateColumn>

    Comment

    • MassiveMohit
      New Member
      • Nov 2014
      • 3

      #3
      Thanks Frinny for the response, but I have a DataGrid instead of GridView.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Ok,
        The same concept still applies: use the DataGrid.ItemDa taBound Event or modify your template (which is a lot easier to do).

        -Frinny

        Comment

        • MassiveMohit
          New Member
          • Nov 2014
          • 3

          #5
          I modified the template and it worked.
          Thank you so much Frinny. :)

          Comment

          Working...