Using javascript return confirm function within asp.net sub

  • Thread starter Thread starter Kathy Burke
  • Start date Start date
K

Kathy Burke

I'm trying to use the following code to use a javascript return confirm.
Cancel would exit the sub and return the page to its history (-2).

OK would proceed with the asp.net code, i.e., run the Complete() sub.

This is within a page that will take me quite a while to test, so I'd
like to know if I've got this right beforehand. I think I'm missing
something...but not sure what? Never used this before in this way.

...within a Sub...

If varTestStatus = "F" Then
RegisterClientScriptBlock("ConfirmTestFail", "<script
language='javascript'>return confirm(""Click Cancel to
return to the instruction page.\n\nOR...click OK to
continue running this code."");self.history.go(-2);
</script>")
'if Cancel clicked
Complete()
End If

TIA!
Kathy
 
Hi,

I think you mean :

if (!confirm("Click Cancel to return to the instruction page.\n\n
OR...click OK to continue running this code."))
{
self.history.go(-2);
}

I can’t see where you attach this block to event or you meant to use
registerstartupscript. Anyway if I understood you want to call server
side code if the user presses OK. If so you can’t do it the way you
write it, when the client side script took place the server side code
not exists anymore. The best way to so is to cause postback if the user
click "OK"

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Thanks, Natty.

Yes, I'm using RegisterClientScriptBlock. Would the following work from
with asp.net code? If OK, I would like to open a new page
(Proceed.aspx), if Cancel, would like to return to originating html page
(needs history (-1) or it remains blank.

Using RegisterClientScriptBlock, will the following work (clearly this
is not my area of even semi-expertise!). It needs to initiate from code
(not a button). It's in an If statement (e.g., If test_status = "F"
Then...)

RegisterClientScriptBlock("ConfirmFail", "<script
language='javascript'>if(confirm(""TEST FAILED.\n\nClick CANCEL to
return to the instruction.\n\nOR...click OK to continue the process
selected."")){parent.right.location='Proceed.aspx';;return true} else
{parent.right.history.go(-1);}</script>")

I would then move the "continue process" code to the proceed.aspx page.

Am I still off track?

BTW, this is a left/right frame setup.

Thanks again.
Kathy
 
Back
Top