javascript confirm fires after deletion instead of before

  • Thread starter Thread starter TJS
  • Start date Start date
T

TJS

javascript "confirm" fires after deletion instead of before deletion.
how do I get this to stop the processing ?



code
==================
Sub ShowAlert(ByVal s As string)
RegisterClientScriptBlock("CSP-showconfirm-function", _
"<s"+"cript language=""JavaScript"">" & vbCrLf & _
"function Show_confirm(s) {" & _
"return confirm(s); " & _
"}" & vbCrLf & _
"</s" + "cript>")
RegisterStartupScript("CSP-showconfirm", _
"<s"+"cript language=""JavaScript"">Show_confirm('" & _
s & "');</s"+"cript>")
End Sub


Sub Delete_Click(Sender As Object, e as System.Web.UI.ImageClickEventArgs)
call ShowAlert("Delete?")
Call delete()
End Sub


......

<form ...
<asp:ImageButton id="Btn_Delete" onclick="Delete_Click" Runat="Server"
ImageUrl="~/img/delete.gif" />
</form>
 
Instead of all this Register... mess put just one line in the Page_Load
event:

Btn_Delete.Attributes("onclick")="return confirm('Delete?');"

And get rid of "call ShowAlert("Delete?")" either.

Eliyahu
 
TJS said:
javascript "confirm" fires after deletion instead of before deletion.
how do I get this to stop the processing ?



code
==================
Sub ShowAlert(ByVal s As string)
RegisterClientScriptBlock("CSP-showconfirm-function", _
"<s"+"cript language=""JavaScript"">" & vbCrLf & _
"function Show_confirm(s) {" & _
"return confirm(s); " & _
"}" & vbCrLf & _
"</s" + "cript>")
RegisterStartupScript("CSP-showconfirm", _
"<s"+"cript language=""JavaScript"">Show_confirm('" & _
s & "');</s"+"cript>")
End Sub


Sub Delete_Click(Sender As Object, e as
System.Web.UI.ImageClickEventArgs) call ShowAlert("Delete?")
Call delete()
End Sub


.....

<form ...
<asp:ImageButton id="Btn_Delete" onclick="Delete_Click" Runat="Server"
ImageUrl="~/img/delete.gif" />
</form>

What happens in your Delete_Click is this:
1) you add some script blocks to be rendered eventually
2) then you call delete ()
After this the page renders & gets sent to the browser,
which will display the confirm (which has nowhere to return to)


Hans Kesting
 
tried tht , but it does not fire at all


Eliyahu Goldin said:
Instead of all this Register... mess put just one line in the Page_Load
event:

Btn_Delete.Attributes("onclick")="return confirm('Delete?');"

And get rid of "call ShowAlert("Delete?")" either.

Eliyahu
 
the confirm box does not fire , the event fires


Eliyahu Goldin said:
What doesn't fire? The confirm box or the server event? Check if the
server
event set up correctly.

Eliyahu
 
What doesn't fire? The confirm box or the server event? Check if the server
event set up correctly.

Eliyahu
 
Try

Btn_Delete.Attributes("onclick")=String.Format("\"{0}\"", "return
confirm('Delete?');")

Eliyahu
 
throws this error


Compiler Error Message: BC30518: Overload resolution failed because no
accessible 'Format' can be called with these arguments:
 
Back
Top