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 14 5672
On Mon, 29 May 2006 19:00:07 +0200, "Averell" <av*****@iets.uk> 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
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" <pk**********@73rdstreet.com> wrote in message
news:sd********************************@4ax.com... On Mon, 29 May 2006 19:00:07 +0200, "Averell" <av*****@iets.uk> 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
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 !!
"olrt" <ol**@ifrance.com> wrote in
news:11*********************@u72g2000cwu.googlegro 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!~*
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<-------------------------------------------------------
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
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
<Ca**********@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr 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
ASP.NET20: Simple gridview ex. with del. confirm: http://www.hellobasic.com/cgi-bin/fo...num=1137191330
"Averell" <er*@ifgfets.uk> schreef in bericht
news:eC**************@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.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
<Ca**********@gmail.com> wrote in message news:11**********************@y43g2000cwc.googlegr 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
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('Dele te?');")
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.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
<Ca**********@gmail.com> wrote in message news:11**********************@y43g2000cwc.googlegr 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
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,
<Ca**********@gmail.com> schreef in bericht
news:11**********************@j55g2000cwa.googlegr oups.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('Dele te?');")
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.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
<Ca**********@gmail.com> wrote in message news:11**********************@y43g2000cwc.googlegr 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 >
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.
<Ca**********@gmail.com> schreef in bericht
news:11**********************@j55g2000cwa.googlegr oups.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('Dele te?');")
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.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
<Ca**********@gmail.com> wrote in message news:11**********************@y43g2000cwc.googlegr 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 >
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. <Ca**********@gmail.com> schreef in bericht news:11**********************@j55g2000cwa.googlegr oups.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('Dele te?');")
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.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
<Ca**********@gmail.com> wrote in message news:11**********************@y43g2000cwc.googlegr 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 >
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,
<Ca**********@gmail.com> schreef in bericht
news:11*********************@u72g2000cwu.googlegro ups.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. <Ca**********@gmail.com> schreef in bericht news:11**********************@j55g2000cwa.googlegr oups.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('Dele te?');") > > 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.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 >> >> >> <Ca**********@gmail.com> wrote in message >> news:11**********************@y43g2000cwc.googlegr 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 >> > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter Afonin |
last post by:
Hello:
I'm deleteing data using Datagrid, then rebind it. For some reason
ItemDataBound event doesn't fire after DeleteCommand. Why is this? Is it by
design, or I'm missing something? I have...
|
by: Rodger Dusatko |
last post by:
After entering the sql statement da.deletecommand.commandtext = "Delete from
Users where username = @username" I set the parameter to the username I wish
to delete.
This successfully deletes the...
|
by: Nathan Sokalski |
last post by:
I have a DataList that has an Button as one of the controls in it's
ItemTemplate. The Button has a CommandName="delete" attribute, but when I
click it the DeleteCommand event doesn't even get...
|
by: |
last post by:
Hi,
How to add the DeleteCommand="delete from table where ..."
related to a gridview in VB.Net, because i have no tag <asp:SqlDataSource >?
This is the content of file grid.asp:...
|
by: phil |
last post by:
Hi,
The connection and DeleteCommand of a gridview are defined in the aspx file
like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"...
|
by: Jason Barnett |
last post by:
I dropped a DataGrid control onto a Web UserControl (.ascx) and added columns
for Editing and Deleting data. At first, I had everything working; when the
edit button was clicked the row entered...
|
by: jobs |
last post by:
Gridview with datasoure with deletecommand. Why do I need an event
handler? Isn't this enough?
I know this code has worked when I use a fielditemtemplate
<asp:GridView ID="RouteGridView"...
|
by: renatois |
last post by:
DeleteCommand in SqlDataSource using DetailsView
Hi guys,
Figure that:
- I have two related tables by IDName:
1 - table Name (fields: IDName, Name)
2 - table Products (fields: IDProduct,...
|
by: Andy B |
last post by:
I added a LINQ classes (dbml) file to my web application project and drug a
sql server database table from the server explorer onto the o/r designer. I
saved and closed the designer after that. I...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |