Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to add a warning to DeleteCommand of gridview?

Reply
Thread Tools

how to add a warning to DeleteCommand of gridview?

 
 
Averell
Guest
Posts: n/a
 
      05-29-2006
Hi,

I made a gridview with VWD. The gridview has the Delete button set
(ShowDeleteButton="True" in the <asp:CommandField>).
It works perfect, but i would like to add a warning before the record is
deleted to prevent deleting a wrong record.
I did this in the code-behind file:
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting
Dim jv As String
jv = "<script language='javascript'>" _
& " alert('beware!');" _
& "if (! confirm('if you want to delete it, click on OK'));" _
& " {window.location.href='mult.aspx'};" _
& "</script>"
Response.Write(jv)
End Sub

I see effectively the warning, but when i click on OK or on Cancel of the
Confirm, in both cases the record is deleted.
Is it possible to prevent that, and if yes, how?

Thanks for any hints
Averell



 
Reply With Quote
 
 
 
 
PeterKellner
Guest
Posts: n/a
 
      05-29-2006
On Mon, 29 May 2006 19:00:07 +0200, "Averell" <(E-Mail Removed)> wrote:

>Hi,
>
>I made a gridview with VWD. The gridview has the Delete button set
>(ShowDeleteButton="True" in the <asp:CommandField>).
>It works perfect, but i would like to add a warning before the record is
>deleted to prevent deleting a wrong record.
>I did this in the code-behind file:
>Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
>System.Web.UI.WebControls.GridViewDeleteEventArgs ) Handles
>GridView1.RowDeleting
> Dim jv As String
> jv = "<script language='javascript'>" _
> & " alert('beware!');" _
> & "if (! confirm('if you want to delete it, click on OK'));" _
> & " {window.location.href='mult.aspx'};" _
> & "</script>"
> Response.Write(jv)
>End Sub
>
>I see effectively the warning, but when i click on OK or on Cancel of the
>Confirm, in both cases the record is deleted.
>Is it possible to prevent that, and if yes, how?
>
>Thanks for any hints
>Averell
>
>


You need to return the results of confirm.
Peter Kellner
http://peterkellner.net
 
Reply With Quote
 
 
 
 
Bob
Guest
Posts: n/a
 
      05-30-2006
Peter, i made a function and returned the confirm result, but even clicking
on Cancel, the record is deleted ...
I inserted an ALERT after the 'return false' and it's not executed. The Java
code stops indeed, but not the VB code deleting the row.

Is this the right way to proceed?
thanks


Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
GridView1.RowDeleting
Dim jv As String
jv = "<script language='javascript'>" _
& "function check()" _
& "{" _
& " alert('let op');" _
& " var ok=confirm('if you want to delete it, click on OK');" _
& " if (!ok)" _
& " {" _
& " window.location.href='mult.aspx';" _
& " return false;" _
& " alert('this is not shown');" _
& "};" _
& "};" _
& "check();" _
& "</script>"
Response.Write(jv)
End Sub

"PeterKellner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 29 May 2006 19:00:07 +0200, "Averell" <(E-Mail Removed)> wrote:
>
> >Hi,
> >
> >I made a gridview with VWD. The gridview has the Delete button set
> >(ShowDeleteButton="True" in the <asp:CommandField>).
> >It works perfect, but i would like to add a warning before the record is
> >deleted to prevent deleting a wrong record.
> >I did this in the code-behind file:
> >Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As
> >System.Web.UI.WebControls.GridViewDeleteEventArgs ) Handles
> >GridView1.RowDeleting
> > Dim jv As String
> > jv = "<script language='javascript'>" _
> > & " alert('beware!');" _
> > & "if (! confirm('if you want to delete it, click on OK'));" _
> > & " {window.location.href='mult.aspx'};" _
> > & "</script>"
> > Response.Write(jv)
> >End Sub
> >
> >I see effectively the warning, but when i click on OK or on Cancel of the
> >Confirm, in both cases the record is deleted.
> >Is it possible to prevent that, and if yes, how?
> >
> >Thanks for any hints
> >Averell
> >
> >

>
> You need to return the results of confirm.
> Peter Kellner
> http://peterkellner.net



 
Reply With Quote
 
olrt
Guest
Posts: n/a
 
      05-30-2006
You should look the example at :
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspnetcon/html/2c688b1a-93a4-4dad-b82b-63974bdbb13e.htm

Then you might paste the code of Page_Load into your Row_Deleting event
handler.
Don't forget to Cancel delete by default !!

 
Reply With Quote
 
NumbLock
Guest
Posts: n/a
 
      05-30-2006
"olrt" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) ups.com:

> ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspnetcon/html/2
> c688b1a-93a4-4dad-b82b-63974bdbb13e.htm


Check out this site:

http://www.codeproject.com/aspnet/Ni...pleControl.asp

Ning Liang packaged up some javascript into a web control that will
return the results of it's confirm action in the request.form. You can
trap the delete button event, call the msgbox1.confirm function and trap
for the form variable in the load or prerender event since the
msgbox1.confirm does a postback.



--
*~!NumbLock!~*
 
Reply With Quote
 
olrt
Guest
Posts: n/a
 
      05-30-2006
With VWD 2005, I've the following message when I click to continue :

-----------------------------------------------------------------8<-------------------------------------------------------
Invalid postback or callback argument. Event validation is enabled
using <pages enableEventValidation="true"/> in configuration or <%@
Page EnableEventValidation="true" %> in a page. For security purposes,
this feature verifies that arguments to postback or callback events
originate from the server control that originally rendered them. If
the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to
register the postback or callback data for validation.
-----------------------------------------------------------------8<-------------------------------------------------------

 
Reply With Quote
 
CaffieneRush@gmail.com
Guest
Posts: n/a
 
      05-30-2006
What Peter Kellner means is that you need to inject some clientside
javascript when you're creating your delete button and return the
results of the Confirm.
In this scenario the RowDeleting serverside event would not even fire
if the user clicks Cancel because the delete click would be cancelled
on the clientside.

http://msdn.microsoft.com/library/de...idViewEx10.asp
Do a search on the word 'OnClientClick' and you can see some specific
code on delete confirmation.

Regards,
Andy

 
Reply With Quote
 
Averell
Guest
Posts: n/a
 
      05-31-2006
Hi, i'm a little confused with all those solutions. Meanwhile i did this and
i feel i'm close to the solution (??).
The only thing i miss is how to pass the result of the function check() to
VB.
Thanks

Dim jv As String
jv = "function check()" _
& "{" _
& " alert('warning');" _
& " var ok=confirm(if you want to delete; click on OK');" _
& " if (!ok)" _
& " {" _
& " window.location.href='mult.aspx';" _
& " return false;" _
& "};" _
& "};" _
& "check();"

Page.ClientScript.RegisterClientScriptBlock(Me.Get Type(), "myscript", jv,
True)

dim x as string
x= result of function check() : HOW TO DO THIS?
if x="False" then e.cancel=True


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> What Peter Kellner means is that you need to inject some clientside
> javascript when you're creating your delete button and return the
> results of the Confirm.
> In this scenario the RowDeleting serverside event would not even fire
> if the user clicks Cancel because the delete click would be cancelled
> on the clientside.
>
>

http://msdn.microsoft.com/library/de...idViewEx10.asp
> Do a search on the word 'OnClientClick' and you can see some specific
> code on delete confirmation.
>
> Regards,
> Andy
>



 
Reply With Quote
 
Edwin Knoppert
Guest
Posts: n/a
 
      05-31-2006
ASP.NET20: Simple gridview ex. with del. confirm:

http://www.hellobasic.com/cgi-bin/fo...num=1137191330



"Averell" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hi, i'm a little confused with all those solutions. Meanwhile i did this
> and
> i feel i'm close to the solution (??).
> The only thing i miss is how to pass the result of the function check() to
> VB.
> Thanks
>
> Dim jv As String
> jv = "function check()" _
> & "{" _
> & " alert('warning');" _
> & " var ok=confirm(if you want to delete; click on OK');" _
> & " if (!ok)" _
> & " {" _
> & " window.location.href='mult.aspx';" _
> & " return false;" _
> & "};" _
> & "};" _
> & "check();"
>
> Page.ClientScript.RegisterClientScriptBlock(Me.Get Type(), "myscript", jv,
> True)
>
> dim x as string
> x= result of function check() : HOW TO DO THIS?
> if x="False" then e.cancel=True
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>> What Peter Kellner means is that you need to inject some clientside
>> javascript when you're creating your delete button and return the
>> results of the Confirm.
>> In this scenario the RowDeleting serverside event would not even fire
>> if the user clicks Cancel because the delete click would be cancelled
>> on the clientside.
>>
>>

> http://msdn.microsoft.com/library/de...idViewEx10.asp
>> Do a search on the word 'OnClientClick' and you can see some specific
>> code on delete confirmation.
>>
>> Regards,
>> Andy
>>

>
>



 
Reply With Quote
 
olrt
Guest
Posts: n/a
 
      05-31-2006

Edwin Knoppert a écrit :

> ASP.NET20: Simple gridview ex. with del. confirm:
>
> http://www.hellobasic.com/cgi-bin/fo...num=1137191330
>


Functional and simple.
Thanks very much !

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
how to add a warning to DeleteCommand of gridview? Averell ASP .Net Web Controls 14 06-01-2006 09:40 AM
How to add the DeleteCommand in aspx.vb file? ASP .Net 0 05-24-2006 02:00 PM
When I click the cancel button of the DataGrid control, it raises DeleteCommand event!!! Why???????? XueWu ASP .Net 0 07-12-2005 01:42 PM
ItemDataBound doesn't fire when I use DeleteCommand Peter Afonin ASP .Net 2 11-19-2003 05:26 PM



Advertisments