Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Redirecting to another page via button

Redirecting to another page via button

Scheduled Pinned Locked Moved ASP.NET
toolsquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #1

    What do i call on a button click event to redirect to another page? I don't want to use a hyperlink, but i'm stumped on what to do. Is this going to be client side script? What do i put in? Cheers Cata

    J M 2 Replies Last reply
    0
    • T Tristan Rhodes

      What do i call on a button click event to redirect to another page? I don't want to use a hyperlink, but i'm stumped on what to do. Is this going to be client side script? What do i put in? Cheers Cata

      J Offline
      J Offline
      Jesse Squire
      wrote on last edited by
      #2

      Take a peek at Response.Redirect and Server.Transfer on MSDN. You could also hijack the server form to force the data to post to a new page.

      btnGo.Attributes.Add("onclick", "document.forms[0].action = 'http://www.server.com/mypage.aspx';");

      Hope that helps. :) --Jesse

      T 1 Reply Last reply
      0
      • T Tristan Rhodes

        What do i call on a button click event to redirect to another page? I don't want to use a hyperlink, but i'm stumped on what to do. Is this going to be client side script? What do i put in? Cheers Cata

        M Offline
        M Offline
        MrMicrosoftvn
        wrote on last edited by
        #3

        use window.location in your javascript to redirect

        1 Reply Last reply
        0
        • J Jesse Squire

          Take a peek at Response.Redirect and Server.Transfer on MSDN. You could also hijack the server form to force the data to post to a new page.

          btnGo.Attributes.Add("onclick", "document.forms[0].action = 'http://www.server.com/mypage.aspx';");

          Hope that helps. :) --Jesse

          T Offline
          T Offline
          Tristan Rhodes
          wrote on last edited by
          #4

          Hi jesse. I got the Redirect working, thanks. But i don't understand this line and the documentation in visual studio is fuzzy: btnGo.Attributes.Add("onclick", "document.forms[0].action = 'http://www.server.com/mypage.aspx';"); what does it do? Cheers Cata

          T J 2 Replies Last reply
          0
          • T Tristan Rhodes

            Hi jesse. I got the Redirect working, thanks. But i don't understand this line and the documentation in visual studio is fuzzy: btnGo.Attributes.Add("onclick", "document.forms[0].action = 'http://www.server.com/mypage.aspx';"); what does it do? Cheers Cata

            T Offline
            T Offline
            Tim Friesen
            wrote on last edited by
            #5

            The Catalyst wrote: I got the Redirect working, thanks. But i don't understand this line and the documentation in visual studio is fuzzy: btnGo.Attributes.Add("onclick", "document.forms[0].action = 'http://www.server.com/mypage.aspx';"); This code assumes that you have a System.Web.UI.WebControls.Button on your form. All it really does is add the onclick attribute to the rendered button control. For instance: The script that is being run is changing the value of the rendered Form's Action attribute. This attribute stores the URL to post the current form to. Generally in ASP.NET, the form posts to itself, so this is looking like an override of sorts, to post to a different page when the user clicks the Go button. Tim Friesen tntfriesen1@hotmail.com

            1 Reply Last reply
            0
            • T Tristan Rhodes

              Hi jesse. I got the Redirect working, thanks. But i don't understand this line and the documentation in visual studio is fuzzy: btnGo.Attributes.Add("onclick", "document.forms[0].action = 'http://www.server.com/mypage.aspx';"); what does it do? Cheers Cata

              J Offline
              J Offline
              Jesse Squire
              wrote on last edited by
              #6

              Tim hit the nail right on the head, and did a better job expaining it then I could have. Thanks, Tim. :) The reason that I included that snipit in my original post is that ASP.NET does not have an "out of the box" way of manipulating the page to which your form data will be posted. ASP.NET assumes that you will always be posting back to the same page. As Tim mentioned, 99% of the time, you'll want your page to post back to itself for server-side processing. In my experience, the most common place where you'd want to post data to another page is when you find yourself interacting with a legacy ASP or CGI application. They will sometimes expect data coming in from a POST operation (as opposed to data passed on the query string.) --Jesse

              T 1 Reply Last reply
              0
              • J Jesse Squire

                Tim hit the nail right on the head, and did a better job expaining it then I could have. Thanks, Tim. :) The reason that I included that snipit in my original post is that ASP.NET does not have an "out of the box" way of manipulating the page to which your form data will be posted. ASP.NET assumes that you will always be posting back to the same page. As Tim mentioned, 99% of the time, you'll want your page to post back to itself for server-side processing. In my experience, the most common place where you'd want to post data to another page is when you find yourself interacting with a legacy ASP or CGI application. They will sometimes expect data coming in from a POST operation (as opposed to data passed on the query string.) --Jesse

                T Offline
                T Offline
                Tristan Rhodes
                wrote on last edited by
                #7

                I'm new to asp.net, and web site design in general. Is asp.net designed to function as some kind of template on a singular page with updating fields? I was thinking of making a site with multiple pages for different areas, and then linking them all together. But i see a lot of sites out there that use the same header / border / menu side bar, with different content depending on what buttons are pressed. I'm looking at a load of design tutorials atm, but i'm curious about overall design strategies for asp.net. Cata

                J 1 Reply Last reply
                0
                • T Tristan Rhodes

                  I'm new to asp.net, and web site design in general. Is asp.net designed to function as some kind of template on a singular page with updating fields? I was thinking of making a site with multiple pages for different areas, and then linking them all together. But i see a lot of sites out there that use the same header / border / menu side bar, with different content depending on what buttons are pressed. I'm looking at a load of design tutorials atm, but i'm curious about overall design strategies for asp.net. Cata

                  J Offline
                  J Offline
                  Jesse Squire
                  wrote on last edited by
                  #8

                  ASP.NET doesn't really restrict you to any one way of constructing an application. The structure and flow are really more a matter of personal preference. Some people prefer to segment the site into different pages, each with a specific function. Some prefer to use a single page as a template and change the content as needed. Some mix the approaches... and the list goes on. :) IMHO, there isn't really a right or wrong way. It is a design choice, each with their own advantages and drawbacks... kind of like selecting a language to develop in. The users of your site won't discern a difference in the implementation... so, I'd encourage you to go with what is comfortable for you. --Jesse

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups