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:
Expand|Select|Wrap|Line Numbers
- <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:
Expand|Select|Wrap|Line Numbers
- 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
- }
Please help!