how to add a warning to DeleteCommand of gridview?

how to add a warning to DeleteCommand of gridview?

am 29.05.2006 19:00:07 von averell

Hi,

I made a gridview with VWD. The gridview has the Delete button set
(ShowDeleteButton="True" in the ).
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 = ""
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

Re: how to add a warning to DeleteCommand of gridview?

am 29.05.2006 21:56:00 von PeterKellner

On Mon, 29 May 2006 19:00:07 +0200, "Averell" wrote:

>Hi,
>
>I made a gridview with VWD. The gridview has the Delete button set
>(ShowDeleteButton="True" in the ).
>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 = ""
> 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

Re: how to add a warning to DeleteCommand of gridview?

am 30.05.2006 10:43:48 von Bob

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 = ""
Response.Write(jv)
End Sub

"PeterKellner" wrote in message
news:sdkm72lelrgl11njic1cp6sto563ib86dr@4ax.com...
> On Mon, 29 May 2006 19:00:07 +0200, "Averell" wrote:
>
> >Hi,
> >
> >I made a gridview with VWD. The gridview has the Delete button set
> >(ShowDeleteButton="True" in the ).
> >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 = ""
> > 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

Re: how to add a warning to DeleteCommand of gridview?

am 30.05.2006 11:13:28 von olrt

You should look the example at :
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspne tcon/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 !!

Re: how to add a warning to DeleteCommand of gridview?

am 30.05.2006 17:20:32 von NumbLock

"olrt" wrote in
news:1148980408.206982.11150@u72g2000cwu.googlegroups.com:

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

Check out this site:

http://www.codeproject.com/aspnet/NingLiangSimpleControl.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!~*

Re: how to add a warning to DeleteCommand of gridview?

am 30.05.2006 19:51:32 von olrt

With VWD 2005, I've the following message when I click to continue :

------------------------------------------------------------ -----8<-------------------------------------------------------
Invalid postback or callback argument. Event validation is enabled
using 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<----------------------------------------------------- --

Re: how to add a warning to DeleteCommand of gridview?

am 30.05.2006 23:07:25 von Andrew Lam

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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
Do a search on the word 'OnClientClick' and you can see some specific
code on delete confirmation.

Regards,
Andy

Re: how to add a warning to DeleteCommand of gridview?

am 31.05.2006 08:55:10 von averell

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.GetType(), "myscript", jv,
True)

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


wrote in message
news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
> Do a search on the word 'OnClientClick' and you can see some specific
> code on delete confirmation.
>
> Regards,
> Andy
>

Re: how to add a warning to DeleteCommand of gridview?

am 31.05.2006 10:35:42 von Edwin Knoppert

ASP.NET20: Simple gridview ex. with del. confirm:

http://www.hellobasic.com/cgi-bin/forum/YaBB.pl?board=dotnet ;action=display;num=1137191330



"Averell" schreef in bericht
news:eCgsy8HhGHA.4656@TK2MSFTNGP04.phx.gbl...
> 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.GetType(), "myscript", jv,
> True)
>
> dim x as string
> x= result of function check() : HOW TO DO THIS?
> if x="False" then e.cancel=True
>
>
> wrote in message
> news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
>> Do a search on the word 'OnClientClick' and you can see some specific
>> code on delete confirmation.
>>
>> Regards,
>> Andy
>>
>
>

Re: how to add a warning to DeleteCommand of gridview?

am 31.05.2006 15:38:25 von olrt

Edwin Knoppert a =E9crit :

> ASP.NET20: Simple gridview ex. with del. confirm:
>
> http://www.hellobasic.com/cgi-bin/forum/YaBB.pl?board=3Ddotn et;action=3Dd=
isplay;num=3D1137191330
>=20

Functional and simple.
Thanks very much !

Re: how to add a warning to DeleteCommand of gridview?

am 31.05.2006 21:01:25 von Andrew Lam

I finally see where the confusion comes from.
The return we are talking about is not a return to the serverside code
but to the button's click event. So cancel will cancel the click event
while a confirm will continue with the click which would then go onto
trigger a postback to the server.

Take a look at Edwin's code in this thread to see a complete example of
this in action.
My only suggestion is that the line below can be simplified within
Default2.aspx.vb:
If b IsNot Nothing Then b.Attributes.Add("onclick",
"javascript:window.event.returnValue=confirm('Delete?');")

to:
If b IsNot Nothing Then b.OnClientClick = "return confirm('Delete?');"

Regards,
Andy

ps. If you are still resistant to this simple solution then you can use
javascript to write the value of your ok variable to a hidden field in
the page and check this hidden field on the postback.

Averell wrote:
> 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.GetType(), "myscript", jv,
> True)
>
> dim x as string
> x= result of function check() : HOW TO DO THIS?
> if x="False" then e.cancel=True
>
>
> wrote in message
> news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
> > Do a search on the word 'OnClientClick' and you can see some specific
> > code on delete confirmation.
> >
> > Regards,
> > Andy
> >

Re: how to add a warning to DeleteCommand of gridview?

am 31.05.2006 23:17:05 von Edwin Knoppert

I never understood the differences myself.
For my code i was looking for a simple click-abort (on no, abort), that's
all..
However afaik at that time the return statement itself was insufficient
somehow and still produced a round-trip??

I forgot what exactly happend at that time, maybe someone can shed some
light on these differences?

Thanks,



schreef in bericht
news:1149102085.178478.127330@j55g2000cwa.googlegroups.com.. .
>I finally see where the confusion comes from.
> The return we are talking about is not a return to the serverside code
> but to the button's click event. So cancel will cancel the click event
> while a confirm will continue with the click which would then go onto
> trigger a postback to the server.
>
> Take a look at Edwin's code in this thread to see a complete example of
> this in action.
> My only suggestion is that the line below can be simplified within
> Default2.aspx.vb:
> If b IsNot Nothing Then b.Attributes.Add("onclick",
> "javascript:window.event.returnValue=confirm('Delete?');")
>
> to:
> If b IsNot Nothing Then b.OnClientClick = "return confirm('Delete?');"
>
> Regards,
> Andy
>
> ps. If you are still resistant to this simple solution then you can use
> javascript to write the value of your ok variable to a hidden field in
> the page and check this hidden field on the postback.
>
> Averell wrote:
>> 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.GetType(), "myscript", jv,
>> True)
>>
>> dim x as string
>> x= result of function check() : HOW TO DO THIS?
>> if x="False" then e.cancel=True
>>
>>
>> wrote in message
>> news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
>> > Do a search on the word 'OnClientClick' and you can see some specific
>> > code on delete confirmation.
>> >
>> > Regards,
>> > Andy
>> >
>

Re: how to add a warning to DeleteCommand of gridview?

am 31.05.2006 23:19:46 von Edwin Knoppert

Btw, imo by removing "javascript:" from the line you assume that the browser
interpret's the code as javascript by default.
Maybe you better keep "javascript:" in at all times.
I have not investigated this but i assumed this.



schreef in bericht
news:1149102085.178478.127330@j55g2000cwa.googlegroups.com.. .
>I finally see where the confusion comes from.
> The return we are talking about is not a return to the serverside code
> but to the button's click event. So cancel will cancel the click event
> while a confirm will continue with the click which would then go onto
> trigger a postback to the server.
>
> Take a look at Edwin's code in this thread to see a complete example of
> this in action.
> My only suggestion is that the line below can be simplified within
> Default2.aspx.vb:
> If b IsNot Nothing Then b.Attributes.Add("onclick",
> "javascript:window.event.returnValue=confirm('Delete?');")
>
> to:
> If b IsNot Nothing Then b.OnClientClick = "return confirm('Delete?');"
>
> Regards,
> Andy
>
> ps. If you are still resistant to this simple solution then you can use
> javascript to write the value of your ok variable to a hidden field in
> the page and check this hidden field on the postback.
>
> Averell wrote:
>> 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.GetType(), "myscript", jv,
>> True)
>>
>> dim x as string
>> x= result of function check() : HOW TO DO THIS?
>> if x="False" then e.cancel=True
>>
>>
>> wrote in message
>> news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
>> > Do a search on the word 'OnClientClick' and you can see some specific
>> > code on delete confirmation.
>> >
>> > Regards,
>> > Andy
>> >
>

Re: how to add a warning to DeleteCommand of gridview?

am 01.06.2006 01:07:20 von Andrew Lam

Fair point about assuming javascript. It is better to be safe so code
below has be changed.
If b IsNot Nothing Then b.OnClientClick = "javascript:return
confirm('Delete?');"

I don't understand how a postback could have occured after returning
false to the control's OnClick event.
The line below should cause the button to never postback to the server
no matter how many time it is clicked.
If b IsNot Nothing Then b.OnClientClick = "javascript:return false;"

Regards,
Andy

Edwin Knoppert wrote:
> Btw, imo by removing "javascript:" from the line you assume that the browser
> interpret's the code as javascript by default.
> Maybe you better keep "javascript:" in at all times.
> I have not investigated this but i assumed this.
>
>
>
> schreef in bericht
> news:1149102085.178478.127330@j55g2000cwa.googlegroups.com.. .
> >I finally see where the confusion comes from.
> > The return we are talking about is not a return to the serverside code
> > but to the button's click event. So cancel will cancel the click event
> > while a confirm will continue with the click which would then go onto
> > trigger a postback to the server.
> >
> > Take a look at Edwin's code in this thread to see a complete example of
> > this in action.
> > My only suggestion is that the line below can be simplified within
> > Default2.aspx.vb:
> > If b IsNot Nothing Then b.Attributes.Add("onclick",
> > "javascript:window.event.returnValue=confirm('Delete?');")
> >
> > to:
> > If b IsNot Nothing Then b.OnClientClick = "return confirm('Delete?');"
> >
> > Regards,
> > Andy
> >
> > ps. If you are still resistant to this simple solution then you can use
> > javascript to write the value of your ok variable to a hidden field in
> > the page and check this hidden field on the postback.
> >
> > Averell wrote:
> >> 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.GetType(), "myscript", jv,
> >> True)
> >>
> >> dim x as string
> >> x= result of function check() : HOW TO DO THIS?
> >> if x="False" then e.cancel=True
> >>
> >>
> >> wrote in message
> >> news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
> >> > Do a search on the word 'OnClientClick' and you can see some specific
> >> > code on delete confirmation.
> >> >
> >> > Regards,
> >> > Andy
> >> >
> >

Re: how to add a warning to DeleteCommand of gridview?

am 01.06.2006 11:40:38 von Edwin Knoppert

It was a long time ago and i had much to learn about js and asp.net.
I really don't know what happened and at this time i have no time to check
this out unf..
I just polled if one had a similar experiance :)

Thanks,



schreef in bericht
news:1149116840.512829.32710@u72g2000cwu.googlegroups.com...
> Fair point about assuming javascript. It is better to be safe so code
> below has be changed.
> If b IsNot Nothing Then b.OnClientClick = "javascript:return
> confirm('Delete?');"
>
> I don't understand how a postback could have occured after returning
> false to the control's OnClick event.
> The line below should cause the button to never postback to the server
> no matter how many time it is clicked.
> If b IsNot Nothing Then b.OnClientClick = "javascript:return false;"
>
> Regards,
> Andy
>
> Edwin Knoppert wrote:
>> Btw, imo by removing "javascript:" from the line you assume that the
>> browser
>> interpret's the code as javascript by default.
>> Maybe you better keep "javascript:" in at all times.
>> I have not investigated this but i assumed this.
>>
>>
>>
>> schreef in bericht
>> news:1149102085.178478.127330@j55g2000cwa.googlegroups.com.. .
>> >I finally see where the confusion comes from.
>> > The return we are talking about is not a return to the serverside code
>> > but to the button's click event. So cancel will cancel the click event
>> > while a confirm will continue with the click which would then go onto
>> > trigger a postback to the server.
>> >
>> > Take a look at Edwin's code in this thread to see a complete example of
>> > this in action.
>> > My only suggestion is that the line below can be simplified within
>> > Default2.aspx.vb:
>> > If b IsNot Nothing Then b.Attributes.Add("onclick",
>> > "javascript:window.event.returnValue=confirm('Delete?');")
>> >
>> > to:
>> > If b IsNot Nothing Then b.OnClientClick = "return confirm('Delete?');"
>> >
>> > Regards,
>> > Andy
>> >
>> > ps. If you are still resistant to this simple solution then you can use
>> > javascript to write the value of your ok variable to a hidden field in
>> > the page and check this hidden field on the postback.
>> >
>> > Averell wrote:
>> >> 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.GetType(), "myscript",
>> >> jv,
>> >> True)
>> >>
>> >> dim x as string
>> >> x= result of function check() : HOW TO DO THIS?
>> >> if x="False" then e.cancel=True
>> >>
>> >>
>> >> wrote in message
>> >> news:1149023245.227871.240380@y43g2000cwc.googlegroups.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/default.asp?url=/library/e n-us/dnaspp/html/GridViewEx10.asp
>> >> > Do a search on the word 'OnClientClick' and you can see some
>> >> > specific
>> >> > code on delete confirmation.
>> >> >
>> >> > Regards,
>> >> > Andy
>> >> >
>> >
>