473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. <asp:DataGrid ID="dgImportList" runat="server" Width="100%" BorderStyle="Solid" AutoGenerateColumns="False">  
  2.   <AlternatingItemStyle CssClass="tabledata2"></AlternatingItemStyle>
  3.   <ItemStyle CssClass="tabledata1"></ItemStyle>
  4.   <HeaderStyle CssClass="tableHeader2"></HeaderStyle>
  5.   <Columns>
  6.     <asp:BoundColumn DataField="FileName" HeaderText="Name"></asp:BoundColumn>
  7.     <asp:BoundColumn DataField="Date" HeaderText="Date"></asp:BoundColumn>
  8.     <asp:ButtonColumn ButtonType="LinkButton"  Text="Import" CommandName="Import"></asp:ButtonColumn>
  9.     <asp:ButtonColumn ButtonType="LinkButton" Text="Check" CommandName="FormatCheck">
  10.     </asp:ButtonColumn>
  11.     <asp:TemplateColumn>
  12.     <ItemTemplate>
  13.       <asp:LinkButton ID="lbImportTemplate"
  14.         runat="server"
  15.         CausesValidation="false" 
  16.         CommandName="ImportTemplate"
  17.         Text="ImportTemplate"
  18.         OOnClick="ConfirmBtnClickHandler"></asp:LinkButton>
  19.     </ItemTemplate>
  20.   </asp:TemplateColumn>
  21.   </Columns>                                          </asp:DataGrid>

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

Please help!
Nov 17 '14 #1
4 1651
Frinavale
9,735 Expert Mod 8TB
Instead of waiting until the user clicks the link, use the GridView.RowDataBound Event to apply the client click JavaScript code that asks for confirmation.

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

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateColumn>
  2.     <ItemTemplate>
  3.       <asp:LinkButton ID="lbImportTemplate"
  4.         runat="server"
  5.         CausesValidation="false" 
  6.         CommandName="ImportTemplate"
  7.         Text="ImportTemplate"
  8.         OnClick="ConfirmBtnClickHandler"
  9.         OnClientClick="if(!confirm('Are you sure to import this item?')){return false;}"></asp:LinkButton>
  10.     </ItemTemplate>
  11.   </asp:TemplateColumn>
Nov 18 '14 #2
Thanks Frinny for the response, but I have a DataGrid instead of GridView.
Nov 18 '14 #3
Frinavale
9,735 Expert Mod 8TB
Ok,
The same concept still applies: use the DataGrid.ItemDataBound Event or modify your template (which is a lot easier to do).

-Frinny
Nov 18 '14 #4
I modified the template and it worked.
Thank you so much Frinny. :)
Nov 19 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Juba | last post by:
I'd created a Template column on my datagrid which contains a textbox and a button that is shown while on Edit mode. How do I capture the button's click event? It is not like the pre-built ones...
0
by: Andrea Trevisan | last post by:
That's a revival of a known thing I suppose.I hope it's useful. My problem was: I want to have a DataGrid with two Template columns: first with TextBox,second with Button.I want to fire an event...
2
by: Patrick Delifer | last post by:
Hi, I am trying to implement a JS confirm dialog when a user is deleting something off my Datagrid. The problem is that I don't have a Delete button in which case I could write the following...
10
by: Jim Bayers | last post by:
We need to stop students from clicking on the form button more than once. We have a form that students fill out with their credit card information. They click, the form sends the data in xml to...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
2
by: pradeep_TP | last post by:
Hello world, I have a simple datagrid on asp.net web form , in which I am showing a single button column called EDIT. The code in the .aspx files for the same is as below. ...
2
by: Smokey Grindle | last post by:
I have the following on my page... a link button that will send the command name "use" to the command handler and a grid view with the following columns 0 - Template column - just a checkbox...
2
by: cartmann | last post by:
Hi, I have a gridview with a template column. In the template column i have two commandbuttons. When clicking the buttons I enter the cmd_click event - but how do I read in which row the button...
0
by: nityaprashant | last post by:
Hello.. could u plz help me? i have template column inside grid view.. in that one link button called Remove this? when i click on that link button confirmation box like "Are u sure u want...
1
by: rogerford | last post by:
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.