Link to home
Start Free TrialLog in
Avatar of Jahelka
JahelkaFlag for United States of America

asked on

Use QueryString to initiate page, use form POST after

Hello Experts:

Using ASP.net 2.0...  Making transition from classic ASP to ASP.net/VB

I've got an existing classic ASP page that uses form GET/QueryString.  It works great as there are only a few criteria that the page really needs to be able to change the view of a dynamic page that shows database reports.  I am porting this page over to ASP.net and am struggling with the best way to use the new features of ASP.net (and follow ASP.net "best practices"), while maintaining some of the nice features of the existing classic ASP page.

One of the nice things about the classic ASP page, after a user selected the criteria they wanted for their report (and got the "view" they wanted, they could easily copy the URL and share it or post it somewhere (all the criteria for the report was in the URL).  With ASP.net, and all the "pre-wired" stuff, there is a bunch of extra stuff that shows up in the query string, and it certainly isn't as nice to share.  So I think I would like to use POST with this new ASP.net page.  My thought was, I could provide a link (with QueryString) somewhere on the page, and tell the user if they want to share this particular "report view" with someone else, they can copy the provided link and use that.  My idea was, the page would first check the querystring for "page initialization" to set the initial criteria, then use POST after that to exchange information between postbacks.

Problem:  Once someone navigates to the ASP.net page using this query string, the query string doesn't go away after the first postback.  Two problems with this...  I can't figure out whether I'm supposed to be pulling my criteria from the query string to "initialize" or if I should be using the POST form data (I suppose I could with IsPostback).  More importantly, the URL and QueryString doesn't change, but the actual criteria being used for the report DOES change with each postback, and that isn't reflected in the URL, so confusion could easily arise from this.

Maybe I am trying to solve this problem the wrong way and there is a better way to do it.  If you know of a better way, let me know.  But I suppose to solve my immediate problem with the way I'm trying to do it, I would need to know how to clear the querystring as shown in the user's address bar on a post back.
ASKER CERTIFIED SOLUTION
Avatar of Muhammad Ousama Ghazali
Muhammad Ousama Ghazali
Flag of Saudi Arabia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jahelka

ASKER

The strange/extra stuff that appears in the query string would be the ViewState stuff (very long).  I just did a little more digging in to what the ViewState is and how it works.  If I could turn off ViewState and get a nice short QueryString back, that would be the ideal solution.

I'm not currently using response.redirect, as with my classic ASP page, my QueryString is nice and short so I have always been using GET and no POST.

It is starting to sound to me like I need to investigate what I need to do to "manually" maintain state.  I'm currently using a couple of hidden fields that are initially set on a "start up screen" if the desired data is not contained in the QueryString.  Sometimes I use links and Javascript to change those hidden field values.  Other parts of the criteria are set via pull down boxes.  So if I were to disable ViewState, am I correct to assume that I would then need to set the selected property for the correct item in the pull down box manually (along with my hidden field values) on page load like I currently do in my classic ASP?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jahelka

ASKER

Hey mog,

Sorry for the delay getting back.  I have had my head buried in dynamically creating gridviews with template fields AND dynamically adding hyperlinks (was trying to do linkbuttons first) to those template fields based on data in the row.  Spent several days on that.  Could have done the same thing in classic ASP in like 10 minutes.  I feel like I still have a LOT to learn.

I think I have decided on using POST form submission and letting the ViewState do it's thing.  But I still want to provide a link that will allow someone to return to that exact view (using QueryString).  Again, no problem there, I can just look for that and set the necessary variables on load to make that happen.  The original problem in my original question still exists.  How do I get rid of that QueryString after I have processed it?  I don't see how response.redirect would help me in this situation...  If the form needs some variables initialized, how can I do that via response.redirect without using a QueryString (that I'm trying to get rid of)?

I'm starting to think that IF there is QueryString data in the URL, I could use response.redirect to send that QueryString to a helper aspx page, which would take that query string data and place it in a form with hidden fields, then find a way to submit that form data in the helper aspx page back to the original page, which would give me a URL free of QueryString data.  Is something like this possible?

Avatar of Jahelka

ASKER

Something just popped into my head.  I don't ever use session variables...  But maybe process the query string, set session variables, then response.redirect would do the trick...
Avatar of Jahelka

ASKER

This solution got me pointed in the right direction.  My final solution:  If querystring data was available, I put those variables into the session state, then redirected back to page, where I processed the session variables to initialize the form.  Not ideal, but it got the job done.  Thanks mog.