Solved

Message Box Redirect

Posted on 2008-10-20
5
798 Views
Last Modified: 2010-04-21
Hi,

I have a message box that's appearing in javascript from the server side. I had the message box on the server side but it wasn't appearing on screen but remained on the task bar.  I decided to show it in javascript instead so it would appear onscreen.

We need to do server side validation.  This was why I didn't use js to begin with.  When the validation is successful I want to display a message box. If they click OK I want them to be directed to one page. If they click cancel I want them to be redirected to an another page.

I have this working fine for the ok part. When the user clicks ok I can direct them to another. However my problem is that I'm not sure how to redirect them if they press cancel.

At the moment the server side shows a message box. When the user clicks ok they are brought to the javascript. If they click cancel on this they remain on the same page. When they click ok, I can show a second message box. Whether they click ok or cancel they are brought to the relevant page. Is there a way I can do this without showing a second message box?

Can I use my first message box to return a true or false value?

At the moment I only seem to be able to return a true value with my first box. I assume this is because I have put true into the vb code. Is there a way I can look to return both true and false here? I tried something like this but it gave me an error saying there was too many arguments or something like that.

The second box that I generate on the client side can test for true and false values.

Any assistance would be appreciated.

Here's the relevant pieces of code:
'This is my server side code 
Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyAlertBox", "if(window.confirm(Would you like to continue?')){javascript:redirect()}", True)
 
//This is my javascript
function redirect()
{
var ans=window.confirm('Would you like to continue');
if (ans == "true")
  {
    //alert('Yes');
   window.location.href = "myPage1.aspx"; 
   }
 else
 {
    //alert('No');
    window.location.href = "myPage2.aspx"; 
 }
 
}

Open in new window

0
Comment
Question by:xdubit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Expert Comment

by:bluV11t
ID: 22759069
The message box does return true or false boolean value (not string), try this:
function redirect()
{
var ans=window.confirm('Would you like to continue');
if (ans)
  {
   //alert('Yes');
   window.location.href = "myPage1.aspx"; 
   }
 else
 {
    //alert('No');
    window.location.href = "myPage2.aspx"; 
 }
 
}

Open in new window

0
 

Author Comment

by:xdubit
ID: 22759466
Thanks for replying bluV11t

This part of my code was working. The problem was that I wanted to use the true or false value without showing the message box again.

Var ans = window.confirm('Would you like to continue') will show the message box again. I'm already showing this from my vb code. In my vb code I have an,  "if(confirm('Would you like to continue?')){javascript:redirect()}", True).

Do you see the way I have true at the end of this vb statement. I'm inferring that this is what only returns the ok value to the javascript. What I would like to do is if cancel is clicked on this server side message box, then also invoke this javascript function. When I had a stop on the function and pressed cancel it did not invoke the function.

Is there a way to also go to this javascript function when cancel is pressed?

Is there something I can put at the end of my vb code other than true which will invoke my javascript function when either ok or cancel is clicked.

Thanks for help.

0
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 22761495
Why not put what you have in your redirect() function inside RegisterStartupScript()?

For example, instead of

    "if(window.confirm(Would you like to continue?')){javascript:redirect()}"

have the entire thing:

    "if(window.confirm(Would you like to continue?')){window.location.href='myPage1.aspx';}else{window.location.href='myPage2.aspx';}"
0
 

Author Comment

by:xdubit
ID: 22762418
Thanks for your reply Zyloch. It seems like the logical thing to do.

I'll have a go at that when I get to my computer in the morning.

0
 

Author Closing Comment

by:xdubit
ID: 31507831
Thanks Zyloch. That did the trick.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question