473,850 Members | 2,073 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 5277
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
1735
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
3119
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
6298
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 has the attributes "Access.lockfile.9" and is owned by one of the users. I tried to delete it but...
8
25087
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( the table is ): DELETE .date, .,
4
2182
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
1213
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 on ie. Any thoughts
19
10773
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
3877
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
36093
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*)' ../common/tinyXML/include/tinyxml.h:1401: undefined reference to `operator delete(void*)'...
0
9895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10352
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7072
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3178
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.