Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP.net load another page

Options
  • 08-08-2008 3:14pm
    #1
    Registered Users Posts: 221 ✭✭


    Hi All,

    I'm very new to ASP.net and web development in general, so
    sorry if this si something really simple.

    I'm creating a web form which i want to split into 2 pages.
    at the bottom of the first page the user presses continue button.
    At this point I want to gather the details they've entered (already validated)
    and bring up another pagewitht eh second part of the form.

    I can't seemt o figure out how to bring the next page up.
    All my searching brings up people who are using JScript to
    pop up a window.

    Can anyone help ?


«1

Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Just redirect to the second form once you've gathered the details, and saved them somehow.

    Response.Redirect("form2.aspx");


  • Registered Users Posts: 1,028 ✭✭✭Hellm0


    eoin_s wrote: »
    Just redirect to the second form once you've gathered the details, and saved them somehow.

    Response.Redirect("form2.aspx");

    Eoin's got the right idea, you will want to save the objects into session, viewstate or as request data. The form you are saving should represent a business objecthttp://en.wikipedia.org/wiki/Business_object_(computer_science) which then get's saved on the postback of the first page. On the page LOAD of the second page you may wish to call a method which can retreive the object and use that object to save the details from the second form. It's a good idea to break some business processes up into seperate "Steps" if you will but it really depends upon the requirement.


  • Registered Users Posts: 221 ✭✭Elfman


    spot on thanks a million

    apologies for lazy goggling on the subject long week


    Elfman


  • Closed Accounts Posts: 577 ✭✭✭Galtee


    An easier way to get what you want would be to use the PreviousPage property on your current page ( in this example Page2).
    E.G: If you have Page1 and Page2, in Page2 you would add a previous page directive to your ASP.NET source code as follows,

    <%@ PreviousPageType VirtualPath="~/Page1.aspx" %>

    On Page1 you would have a public property like below

    public String GetUser
    {
    get
    {
    return tbUser.Text; // TextBox on Page1
    }
    }

    When you transfer to page2 you would get the value as follows

    SomeUserLabel.Text = Page.PreviousPage.GetUser;

    This should do the trick.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Actually Galtee what that will do is reload the previous page into memory, with a full life cycle execution, and is considered to be very inefficient. Store the data in session or the request. No point in putting it into viewstate as viewstate isn't shared across pages.


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    An even easier way. Put the contents of both pages into one page split by two panels. The second one can be invisible and when they press continue you can switch the first panel to invisible and the second to visible. All the persisting of details will be automatically retained in the viewstate which is possible because it's all one the one page.


  • Registered Users Posts: 9,557 ✭✭✭DublinWriter


    Using server.transfer might be more a more efficient way - the second parameter allows you to save the viewstate.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    I'd be careful with server.transfer - the browser isn't aware that the transfer happened and I've known it to cause problems on postback. Keeping things simple is probable the best solution.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    Can be confusing to the user too.


  • Closed Accounts Posts: 81 ✭✭dzy


    Just submit the values from the form in the first page to the second page.


  • Advertisement
  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    dzy wrote: »
    Just submit the values from the form in the first page to the second page.
    Can you do that in .net?


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    eoin_s wrote: »
    Can you do that in .net?

    You can set the postbackurl of a button as of version 2.0 but it's not a true postback. It does the usual messy Microsoft script crap. Still it's an option, not one I would use, but an option.


  • Closed Accounts Posts: 81 ✭✭dzy


    eoin_s wrote: »
    Can you do that in .net?

    I don't know. I just guessed you could submit a form to another page. It seems like a very basic thing to want to do. Or maybe I simply don't get the ideas around the ASP.NET abstractions :-)


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    dzy wrote: »
    I don't know. I just guessed you could submit a form to another page. It seems like a very basic thing to want to do. Or maybe I simply don't get the ideas around the ASP.NET abstractions :-)

    You can't do it in the basic sense of setting the action property of a form as asp.net automatically generates the action property and always sets it to the same page. Once I got used to that way back when the first version of .net came out it made alot of sense to me and I have never had any need to post to another page. I'm sure there might be some situations where people require it but I can only speak for myself.

    As I said above what the OP is trying to do is best done with 2 panels on the same page and switching their visibility as needed imo. I don't think it needs to be more complicated than that.


  • Closed Accounts Posts: 81 ✭✭dzy


    musician wrote: »
    You can't do it in the basic sense of setting the action property of a form as asp.net automatically generates the action property and always sets it to the same page. Once I got used to that way back when the first version of .net came out it made alot of sense to me and I have never had any need to post to another page. I'm sure there might be some situations where people require it but I can only speak for myself.

    As I said above what the OP is trying to do is best done with 2 panels on the same page and switching their visibility as needed imo. I don't think it needs to be more complicated than that.

    Thanks for the explanation. Isn't it a common thing to want to do though? Say I have a search widget or a login widget that I want to appear on all pages and have post to a search a login page respectively. How does ASP.NET handle this?


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    dzy wrote: »
    Thanks for the explanation. Isn't it a common thing to want to do though? Say I have a search widget or a login widget that I want to appear on all pages and have post to a search a login page respectively. How does ASP.NET handle this?

    There are a myriad ways of dealing with this but the thing about asp.net is it is based on an event model so every button's click can be captured in the code for the page. So a search button's click could be caprtured and you could then redirect to the search results page particularly assuming the search page takes the search term in it's querystring for example (which it should imo).

    The only issue I have with it is once there is more than one button .net will do it's inline scripting jiggery pokery putting script onclikc events on them and so on. Annoying for me as I'm an unobtrusive script nazi these days.


  • Closed Accounts Posts: 81 ✭✭dzy


    musician wrote: »
    There are a myriad ways of dealing with this but the thing about asp.net is it is based on an event model so every button's click can be captured in the code for the page. So a search button's click could be caprtured and you could then redirect to the search results page particularly assuming the search page takes the search term in it's querystring for example (which it should imo).

    The only issue I have with it is once there is more than one button .net will do it's inline scripting jiggery pokery putting script onclikc events on them and so on. Annoying for me as I'm an unobtrusive script nazi these days.

    Thanks again. I dabbled in ASP.NET a few years ago and switched back to PHP (shock horror!) because of these kind of things. I spent a lot of time hacking around the framework to achieve something that the ASP.NET model didn't account for. ASP.NET did save me time on some things, but it was offset by trying to find solutions to these types of problems. In the end I decided that I'd be better off with a penknife than a case of black n' deckers.


  • Closed Accounts Posts: 81 ✭✭dzy


    Disclaimer : I'm not trying to start a religious war here. I'm just stating my personal preference. People may prefer ASP.NET and I'm totally cool with that.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    dzy wrote: »
    Thanks again. I dabbled in ASP.NET a few years ago and switched back to PHP (shock horror!) because of these kind of things. I spent a lot of time hacking around the framework to achieve something that the ASP.NET model didn't account for. ASP.NET did save me time on some things, but it was offset by trying to find solutions to these types of problems. In the end I decided that I'd be better off with a penknife than a case of black n' deckers.

    Well I have no problem with people who chose php. Best tools for the job in hand and so on but having worked with asp.net since it's release way back when I honestly wouldn't use anything else. It's possibly the best thing Microsoft have ever done alongside Visual Studio imo. I don't know of a better free IDE out there than VWD.

    As I said it didn't take me long to get my head around the way it worked or wanted to work I suppose is a better way of putting it :) Once I did I never looked back. It's worth revisiting asp.net these days. Some of the new stuff like Linq, MVC, Dynamic Data, Entity Framework are top notch. Not perfect but excellent none the less.


  • Closed Accounts Posts: 81 ✭✭dzy


    musician wrote: »
    Well I have no problem with people who chose php. Best tools for the job in hand and so on but having worked with asp.net since it's release way back when I honestly wouldn't use anything else. It's possibly the best thing Microsoft have ever done alongside Visual Studio imo. I don't know of a better free IDE out there than VWD.

    As I said it didn't take me long to get my head around the way it worked or wanted to work I suppose is a better way of putting it :) Once I did I never looked back. It's worth revisiting asp.net these days. Some of the new stuff like Linq, MVC, Dynamic Data, Entity Framework are top notch. Not perfect but excellent none the less.

    Cheers. I'm all on for second chances :) I'll download the latest free version of VS.NET and have another go.


  • Advertisement
  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    musician wrote: »
    There are a myriad ways of dealing with this but the thing about asp.net is it is based on an event model so every button's click can be captured in the code for the page. So a search button's click could be caprtured and you could then redirect to the search results page particularly assuming the search page takes the search term in it's querystring for example (which it should imo).

    I don't want to go too off topic, but what's the best way to set a form action on a remote site? Redirecting and using the querystring won't work as it has to be a POST (It's a form that sends info to Realex).


  • Closed Accounts Posts: 577 ✭✭✭Galtee


    Evil Phil wrote: »
    Actually Galtee what that will do is reload the previous page into memory, with a full life cycle execution, and is considered to be very inefficient. Store the data in session or the request. No point in putting it into viewstate as viewstate isn't shared across pages.

    Actually phil, it won't reload the page, it's already loaded when you transfer to the second page and I didn't say I was giving the most efficient way I said the easiest way bearing in mind that the person who posted the original message prefixed it by saying they are new to ASP.

    Also if you want the most efficient way then you wouldn't use session variables either, you'd use the query string.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    eoin_s wrote: »
    I don't want to go too off topic, but what's the best way to set a form action on a remote site? Redirecting and using the querystring won't work as it has to be a POST (It's a form that sends info to Realex).

    I don't know of an easy way but you could programmatically post the info. - http://xneuron.wordpress.com/2007/12/05/programmatically-post-a-form-in-aspnet/

    Putting a standard (non-asp.net) form in an asp.net page where it doesn't reside within the asp.net form might work. I've never tried that though.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Thanks, I will look at that. I took the easy way out and just put an ASP page in the same folder, using roughly the same look and feel. As you need to supply realex with a static template, it just meant that the look and feel was different one step earlier in the process.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    eoin_s wrote: »
    Thanks, I will look at that. I took the easy way out and just put an ASP page in the same folder, using roughly the same look and feel. As you need to supply realex with a static template, it just meant that the look and feel was different one step earlier in the process.

    I'm pretty sure I've used those guys before and we were able to send them a template and they setup the form etc. so we just had to point to it. No need for a form on our side at all. Just looking at it they let us send the info we needed to in the querystring. It's a pay for bin tags page. I think it's the same guys - http://www.eforms.ie/?orgRefCode=sth&formRefCode=binTags&returnUrl=http%3A//www.sdcc.ie. Give them a kick up the arse.


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Thanks again - I didn't have a huge amount of time to do much research, so it could well work through the querystring without any modifications. At the time I just needed to get it up and running ASAP, so just went with the way I knew would work.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Galtee wrote: »
    Actually phil, it won't reload the page, it's already loaded when you transfer to the second page and I didn't say I was giving the most efficient way I said the easiest way bearing in mind that the person who posted the original message prefixed it by saying they are new to ASP.

    Also if you want the most efficient way then you wouldn't use session variables either, you'd use the query string.

    Not in my research it wasn't - if you're referencing a previous page in the manner you suggested then asp.net does indeed follow the steps I've outlined in a my previous post i.e. it reloads the page executing the page life cycle. I would also disagree that it is the easiest way too, its difficult to debug in my experience because of the reload of the previous page.

    Bearing in mind that the person who posted the original message prefixed it by saying they are new to Asp.Net I thought I should highlight the inefficiency for them.

    ASP is a different technology entirely and is not being discussed in this thread.


  • Closed Accounts Posts: 577 ✭✭✭Galtee


    Evil Phil wrote: »
    Not in my research it wasn't - if you're referencing a previous page in the manner you suggested then asp.net does indeed follow the steps I've outlined in a my previous post i.e. it reloads the page executing the page life cycle. I would also disagree that it is the easiest way too, its difficult to debug in my experience because of the reload of the previous page.

    Bearing in mind that the person who posted the original message prefixed it by saying they are new to Asp.Net I thought I should highlight the inefficiency for them.

    ASP is a different technology entirely and is not being discussed in this thread.

    Thanks for the comments.
    1) Just to re-iterate, the source page is already loaded in memory on the server when you transfer (on the server) to the new page so reading variables in the manner I suggested is the easiest way of doing so and adheres to OOA standards of passing information from one object to another.

    2) Obviously I was referencing ASP.NET (since it's a thread on ASP.NET) so to make a point about it being a different technology in the manner you did is just petty.


  • Moderators, Science, Health & Environment Moderators Posts: 8,952 Mod ✭✭✭✭mewso


    I'm sure the OP is fascinated by this helpful asp.net dick measuring contest.


  • Advertisement
  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    eoin_s wrote: »
    I don't want to go too off topic, but what's the best way to set a form action on a remote site? Redirecting and using the querystring won't work as it has to be a POST (It's a form that sends info to Realex).

    HI, I have implemented Realex integration with ASP.net using the redirect method.

    I had to programmatically generate the values required by Realex and then injected a hidden form with these values in it. The last step was to attach an event handler to post the data to Realex.

    It was pretty easy to achieve in the end, and I'm surprised Realex still havent added the technique to its developers page!


This discussion has been closed.
Advertisement