473,542 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Client Side Confirmation on DataGrid "Delete" LinkButton

I have a DataGrid control with a LinkButton command column that deletes the
row. What I want to do is set it up so that there's a client-side Confirm
alert BEFORE the actual Delete command gets called on the server-side. That's
easy to do with normal buttons, etc. as follows...

<asp:Button ID="ConfirmBtn " Text="ConfimMe! "
OnClientClick=" if(!confirm('Ar e you sure?'))return false;"
OnClick="Confir mBtnClickHandle r" Runat="server" />

But OnClientClick, etc. are not supported for the DataGrid LinkButton. So
how could I do this?

Alex
May 2 '06 #1
7 5255
You can always add it by code:
ConfirmBtn.Attr ibutes.Add ("onclick", "if (! confirm('Are you sure?'))
return false;");

- Steve

"Alex Maghen" wrote:
I have a DataGrid control with a LinkButton command column that deletes the
row. What I want to do is set it up so that there's a client-side Confirm
alert BEFORE the actual Delete command gets called on the server-side. That's
easy to do with normal buttons, etc. as follows...

<asp:Button ID="ConfirmBtn " Text="ConfimMe! "
OnClientClick=" if(!confirm('Ar e you sure?'))return false;"
OnClick="Confir mBtnClickHandle r" Runat="server" />

But OnClientClick, etc. are not supported for the DataGrid LinkButton. So
how could I do this?

Alex

May 2 '06 #2
Hi Alex,

For such scenario, as Steve has mentioned, we may need to use code to
programmaticall y add the client script for the button. Also, are you using
the built-in button column in DataGrid as below?

<asp:ButtonColu mn ButtonType="lin kButton" ></asp:ButtonColum n>

If so, it'll be very hard to reference the actual button object at runtime
(so as to custimze it) because the button id is autogenerated and it's
unsafe to locate sub controls through control index. I think you can
consider use template column instead of built-in column for such scenario.
And in VS IDE's designview , it provide the wizard for us to convert a
button column to a template column. For example, the above link button
column can be converted to the below template column:(I add the id for the
link button so that we can referece it later):

=========
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on ID="lbDelete" runat="server"
CausesValidatio n="false" CommandName="" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
==============

Then, in DataGrid's ItemdataBound event, we can use the following code to
locate the linkbutton and add client-sdie script behavior for it:

protected void DataGrid1_ItemC reated(object sender, DataGridItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
LinkButton lb = e.Item.FindCont rol("lbDelete") as LinkButton;

lb.OnClientClic k = "if(!confirm('a re you sure to delete this
item?')){return false;}";

}
}
Hope this helps. If there is anything I missed, please feel free to post
here.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 2 '06 #3
G-d, you're good!!! Now just one question remains about this... In the sample
you gave, everything works but I don't know how to actually create a
server-side function that reacts to this TemplateColumn LinkButton. In your
example below, do I just add an OnClick handler to the <asp:LinkButt on /> ?

Alex
"Steven Cheng[MSFT]" wrote:
Hi Alex,

For such scenario, as Steve has mentioned, we may need to use code to
programmaticall y add the client script for the button. Also, are you using
the built-in button column in DataGrid as below?

<asp:ButtonColu mn ButtonType="lin kButton" ></asp:ButtonColum n>

If so, it'll be very hard to reference the actual button object at runtime
(so as to custimze it) because the button id is autogenerated and it's
unsafe to locate sub controls through control index. I think you can
consider use template column instead of built-in column for such scenario.
And in VS IDE's designview , it provide the wizard for us to convert a
button column to a template column. For example, the above link button
column can be converted to the below template column:(I add the id for the
link button so that we can referece it later):

=========
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on ID="lbDelete" runat="server"
CausesValidatio n="false" CommandName="" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
==============

Then, in DataGrid's ItemdataBound event, we can use the following code to
locate the linkbutton and add client-sdie script behavior for it:

protected void DataGrid1_ItemC reated(object sender, DataGridItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
LinkButton lb = e.Item.FindCont rol("lbDelete") as LinkButton;

lb.OnClientClic k = "if(!confirm('a re you sure to delete this
item?')){return false;}";

}
}
Hope this helps. If there is anything I missed, please feel free to post
here.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 2 '06 #4
So I tried adding an OnClick to the LinkButton in your example below and I
*do* get the event back. But here's the problem - I want to be able to
extract the data from the row of the LinkButton that was actually called but
the prototype for a LinkButton seems to deliver an EventArgs parameter as
opposed to a DataGridCommand EventArgs parameter. So how to I get the data out
of the row that was actually clicked?

"Steven Cheng[MSFT]" wrote:
Hi Alex,

For such scenario, as Steve has mentioned, we may need to use code to
programmaticall y add the client script for the button. Also, are you using
the built-in button column in DataGrid as below?

<asp:ButtonColu mn ButtonType="lin kButton" ></asp:ButtonColum n>

If so, it'll be very hard to reference the actual button object at runtime
(so as to custimze it) because the button id is autogenerated and it's
unsafe to locate sub controls through control index. I think you can
consider use template column instead of built-in column for such scenario.
And in VS IDE's designview , it provide the wizard for us to convert a
button column to a template column. For example, the above link button
column can be converted to the below template column:(I add the id for the
link button so that we can referece it later):

=========
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on ID="lbDelete" runat="server"
CausesValidatio n="false" CommandName="" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
==============

Then, in DataGrid's ItemdataBound event, we can use the following code to
locate the linkbutton and add client-sdie script behavior for it:

protected void DataGrid1_ItemC reated(object sender, DataGridItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
LinkButton lb = e.Item.FindCont rol("lbDelete") as LinkButton;

lb.OnClientClic k = "if(!confirm('a re you sure to delete this
item?')){return false;}";

}
}
Hope this helps. If there is anything I missed, please feel free to post
here.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 2 '06 #5
Thanks for your response Alex,

Actually, for push button or linkbutton in DataGrid or Gridview, their
postback event will be mapped to the ItemCommand event (or RowCommand for
GridView) by the "CommandNam e" attribute. For example, for our link button
in the DataGrid template column, we can add the "Delete" value for the
"CommandNam e" attribute as below:

=============== ========
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on ID="lbDelete" runat="server"
CausesValidatio n="false" CommandName="De lete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
=============== ============

Then, in the DataGrid's "ItemComman d" event, we can can handle the
linkbutton postback as below:

=============== ========
protected void DataGrid1_ItemC ommand(object source,
DataGridCommand EventArgs e)
{
if (e.CommandName == "Delete")
{
Response.Write( "<br/>" + e.CommandName + ": " +
e.Item.ItemInde x);
}
}
=============== ===========

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




May 3 '06 #6
Is there ANYTHING you don't know? :)
Thanks!

Alex

"Steven Cheng[MSFT]" wrote:
Thanks for your response Alex,

Actually, for push button or linkbutton in DataGrid or Gridview, their
postback event will be mapped to the ItemCommand event (or RowCommand for
GridView) by the "CommandNam e" attribute. For example, for our link button
in the DataGrid template column, we can add the "Delete" value for the
"CommandNam e" attribute as below:

=============== ========
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on ID="lbDelete" runat="server"
CausesValidatio n="false" CommandName="De lete"
Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
=============== ============

Then, in the DataGrid's "ItemComman d" event, we can can handle the
linkbutton postback as below:

=============== ========
protected void DataGrid1_ItemC ommand(object source,
DataGridCommand EventArgs e)
{
if (e.CommandName == "Delete")
{
Response.Write( "<br/>" + e.CommandName + ": " +
e.Item.ItemInde x);
}
}
=============== ===========

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




May 3 '06 #7
Thanks for your response Alex,

Sure, the more we've learnt, the more we'll find that we don't know.
Anyway, if there is anything we can help on ASP.NET developing , please
feel free to post here.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 4 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1718
by: Stefan Strasser | last post by:
why is delete an expression and not a statement? (in my draft copy of the standard). I was about to ask the same question about "throw" but found an expression case of throw("return boolvalue ? 5 : throw 5;"). but "delete" neither does exit the scope nor has a return value. any idea? thanks,
13
3084
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL" automatically after programs do "delete p"?
0
6281
by: Nate Harel | last post by:
Hi all, I have a client that who has a Access issue. They keep a "master.mdb" file on their server, and each of the users running Access on their local machine, accesses the file over the network. All is fine, except recently something happened that blocked everyone from making updates to the DB. I checked and found a "master.ldb" file that...
8
25041
by: John Baker | last post by:
Hi: Access 2000 W98! I have a table with numerous records in it, and am attempting to delete certain records that have been selected from it. These are selected based on the ID number in a different table. While I am using the tools in Access for query setup, its easier to show it on here using the SQL for the query, which is as follows(...
4
2167
by: Calvin Lai | last post by:
Hi all, Does anyone know how I could add a confirm (client side) feature on those Delete Linkbutton in DataGrid? Thanks,
3
1206
by: Shawn | last post by:
I have found many cases in that after a row has been deleted from a datagrid using a linkbutton and then hit the browser refresh button the row previous to the origianal delete will as well be removed if there is one. I have attempted to track the refresh in a session variable, but in all honesty would like to disable the refresh button/F5...
19
10730
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is there an existing adapter? Thanks, Daniel.
30
3790
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at the end of the app for example: class test { public: int x;
3
35603
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. Main.cpp:377: undefined reference to `operator delete(void*)' tinyXML/include/tinystr.h:259: undefined reference to `operator delete(void*)'...
0
7330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5246
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.