Confirm box on Page_load

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

Is there a way to do a Javascript confirm box when an aspx page initially
loads (not postback)?

I can make the confirm box come up by doing the following:
***************************************************
<script type="text/javascript">
function CheckForProfile() {
confirm("Do you want to Enter a Profile?");
}
</script>

Sub Page_load()
if not isPostBack then
myBody.Attributes.Add("onload","CheckForProfile();")
end if
end sub

<body id="myBody" runat="server">
**************************************************

But I want to have the user redirect to "/applicant/passport.aspx" if they
push the OK button and just continue on if they press the cancel.

Is there a way to do this?

The confirm window comes up fine but how to I get it to jump to another
page?

Thanks,

Tom
 
<script type="text/javascript">
function CheckForProfile()
{
if(confirm("Do you want to enter a profile?"))
{
window.location=" /applicant/passport.aspx";
}
}
</script>
 
Change your function to one that evaluates the return from confirm....and
then does a windows.location to your URL - you might need to fiddle with the
code a bit as I'm tired :0)

function CheckForProfile() {
var ret = confirm("Do you want to Enter a Profile?");
if (ret) {
window.location=http://www.someplace.com;
window.alert('yes');"
else
window.alert('No');
}
}

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog





tshad said:
Is there a way to do a Javascript confirm box when an aspx page initially
loads (not postback)?

I can make the confirm box come up by doing the following:
***************************************************
<script type="text/javascript">
function CheckForProfile() {
var ret = confirm("Do you want to Enter a Profile?");
if (ret) {window.alert('yes');"
else
window.alert('No');}<"
 
That was it.

Thanks,

Tom
John Timney (MVP) said:
Change your function to one that evaluates the return from confirm....and
then does a windows.location to your URL - you might need to fiddle with
the code a bit as I'm tired :0)

function CheckForProfile() {
var ret = confirm("Do you want to Enter a Profile?");
if (ret) {
window.location=http://www.someplace.com;
window.alert('yes');"
else
window.alert('No');
}
}

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog






var ret = confirm("Do you want to Enter a Profile?");
if (ret) {window.alert('yes');"
else
window.alert('No');}<"
 
Back
Top