Redirecting to another page via button
-
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
-
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
Take a peek at
Response.Redirect
andServer.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
-
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
use window.location in your javascript to redirect
-
Take a peek at
Response.Redirect
andServer.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
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
-
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
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
-
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
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
-
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
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
-
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
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