all groups > vb.net controls > may 2006 >
You're in the

vb.net controls

group:

how to add a warning to DeleteCommand of gridview?


Re: how to add a warning to DeleteCommand of gridview? PeterKellner
5/29/2006 12:56:00 PM
vb.net controls:
[quoted text, click to view]

You need to return the results of confirm.
Peter Kellner
how to add a warning to DeleteCommand of gridview? Averell
5/29/2006 7:00:07 PM
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


Re: how to add a warning to DeleteCommand of gridview? Bob
5/30/2006 12:00:00 AM
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

[quoted text, click to view]

Re: how to add a warning to DeleteCommand of gridview? olrt
5/30/2006 2:13:28 AM
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 !!
Re: how to add a warning to DeleteCommand of gridview? NumbLock
5/30/2006 8:20:32 AM
"olrt" <olrt@ifrance.com> wrote in
news:1148980408.206982.11150@u72g2000cwu.googlegroups.com:

[quoted text, click to view]

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.



--
Re: how to add a warning to DeleteCommand of gridview? olrt
5/30/2006 10:51:32 AM
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<-------------------------------------------------------
Re: how to add a warning to DeleteCommand of gridview? CaffieneRush NO[at]SPAM gmail.com
5/30/2006 2:07:25 PM
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/en-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? Averell
5/31/2006 12:00:00 AM
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


[quoted text, click to view]

Re: how to add a warning to DeleteCommand of gridview? Edwin Knoppert
5/31/2006 12:00:00 AM
ASP.NET20: Simple gridview ex. with del. confirm:

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



"Averell" <erb@ifgfets.uk> schreef in bericht
news:eCgsy8HhGHA.4656@TK2MSFTNGP04.phx.gbl...
[quoted text, click to view]

Re: how to add a warning to DeleteCommand of gridview? olrt
5/31/2006 6:38:25 AM

Edwin Knoppert a =E9crit :

[quoted text, click to view]

Functional and simple.
Thanks very much !
Re: how to add a warning to DeleteCommand of gridview? CaffieneRush NO[at]SPAM gmail.com
5/31/2006 12:01:25 PM
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.

[quoted text, click to view]
Re: how to add a warning to DeleteCommand of gridview? CaffieneRush NO[at]SPAM gmail.com
5/31/2006 4:07:20 PM
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

[quoted text, click to view]
Re: how to add a warning to DeleteCommand of gridview? Edwin Knoppert
5/31/2006 11:17:05 PM
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,



<CaffieneRush@gmail.com> schreef in bericht
news:1149102085.178478.127330@j55g2000cwa.googlegroups.com...
[quoted text, click to view]

Re: how to add a warning to DeleteCommand of gridview? Edwin Knoppert
5/31/2006 11:19:46 PM
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.



<CaffieneRush@gmail.com> schreef in bericht
news:1149102085.178478.127330@j55g2000cwa.googlegroups.com...
[quoted text, click to view]

Re: how to add a warning to DeleteCommand of gridview? Edwin Knoppert
6/1/2006 11:40:38 AM
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,



<CaffieneRush@gmail.com> schreef in bericht
news:1149116840.512829.32710@u72g2000cwu.googlegroups.com...
[quoted text, click to view]

AddThis Social Bookmark Button