Preven page jumping in wizard type application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • splendid9
    New Member
    • Mar 2008
    • 56

    Preven page jumping in wizard type application

    Hi...I have a problem with my website, i am trying to prevent user from jumping to his desired page , tht is directly to page10 frm page2...but mine is just wizard like application, wher user shud pass thru each n every page serially. no chance to go back or jump pages. so cud any pls help with this ASAp and also when trying to jump to middle of the page from outside not within the application.... waiting for any solutions.
    Thanks,..
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Why not just remove links to other pages besides the next page?

    Comment

    • splendid9
      New Member
      • Mar 2008
      • 56

      #3
      No i am asking when user tries to jump to a page , by editing URL

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Originally posted by splendid9
        No i am asking when user tries to jump to a page , by editing URL
        Ok, I have an idea. Do you know how to use the Session object? If you don't, google it, or ask us.

        Create a Session value for "pageLastComple ted" or something like that, and when the user is done with the current page, change the value to the page number. At the Page_Load method of each page, you can get the value of that variable, and see if the current page is the next one in line. If it isn't, you can redirect to the proper page.

        Comment

        • splendid9
          New Member
          • Mar 2008
          • 56

          #5
          Could you please giv me an example how to implement this in session,. Taking Page1.aspx
          Page2.aspx
          PAGE3.ASPX...et c, I understood the concpt, but dont know how to use this.Could you please let me know,.


          Thanks.

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            I'll help out. I don't know what language you are using, but C# and VB.NET are pretty easy to translate between. I'll use C#.

            But note: If your user has been to these pages before, they may still be able to see the pages out of order due to browser caching. Internet Explorer or Firefox will keep local copies of the pages, and some of the code won't be run. But if they try to do anything on the page, then they will be redirected. So you could try to find a way to force no caching, but that's hit or miss.

            Anyway, here are the codebehind pages. Just make sure that whatever triggers the "go to next page" command is linked to the proper method.

            Page1.aspx.cs
            Code:
            protected void Page_Load(object sender, EventArgs e)
            {
            	if (!Page.IsPostBack)
            	{
            		//add session object
            		Session.Add("currentPage", 1);
            	}
            }
            protected void buttonGoToPage2_Click(object sender, EventArgs e)
            {
            	//set current page to next page and redirect.
            	Session["currentPage"] = 2;
            	Response.Redirect("page2.aspx");
            }
            Page2.aspx.cs
            Code:
            protected void Page_Load(object sender, EventArgs e)
            {
            	if (!Page.IsPostBack)
            	{
            		//if the session object isnt null
            		if (Session["currentPage"] != null)
            		{
            			//and the session object isnt the correct number
            			if ((int)Session["currentPage"] != 2)
            			{
            				//send to the correct page
            				Response.Redirect("page" + Session["currentPage"].ToString() + ".aspx");
            			}
            		}
            		//if the object is null, send to first page
            		else
            			Response.Redirect("page1.aspx");
            	}
            }
            protected void buttonGoToPage3_Click(object sender, EventArgs e)
            {
            	//set current page to next page and redirect
            	Session["currentPage"] = 3;
            	Response.Redirect("page3.aspx");
            }
            Page3.aspx.cs
            Code:
            protected void Page_Load(object sender, EventArgs e)
            {
            	if (!Page.IsPostBack)
            	{
            		//if the session object isnt null
            		if (Session["currentPage"] != null)
            		{
            			//and the session object isnt the correct number
            			if ((int)Session["currentPage"] != 3)
            			{
            				//send to the correct page
            				Response.Redirect("page" + Session["currentPage"].ToString() + ".aspx");
            			}
            		}
            		//if the object is null, send to first page
            		else
            			Response.Redirect("page1.aspx");
            
            	}
            }
            Originally posted by splendid9
            Could you please giv me an example how to implement this in session,. Taking Page1.aspx
            Page2.aspx
            PAGE3.ASPX...et c, I understood the concpt, but dont know how to use this.Could you please let me know,.


            Thanks.

            Comment

            • splendid9
              New Member
              • Mar 2008
              • 56

              #7
              Thanks buddy,

              I have copied the code into my theree pages.Page1,2,3 .aspx and checked........ But when i try to change the url to say for example page3 from page1 .......
              ? it is going.......to page3,.....whic h it should'nt...... .....Could u also tell me wht shud be the code in Session, (Global.asax)

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Originally posted by splendid9
                Thanks buddy,

                I have copied the code into my theree pages.Page1,2,3 .aspx and checked........ But when i try to change the url to say for example page3 from page1 ....... ? it is going.......to page3,.....whic h it should'nt...... .....
                So, you want to be able to go back, but not forward? Change the comparison from "not equal" (!=) to greater than (>). That should solve the prob.
                Originally posted by splendid9
                Could u also tell me wht shud be the code in Session, (Global.asax)
                AFAIK, nothing is necessary.

                Comment

                Working...