Showing posts with label querystring. Show all posts
Showing posts with label querystring. Show all posts

Saturday, March 24, 2012

AJAX and the Querystring

Having a slight problem with Atlas/Ajax. I have an item page which displays items based on the item id being passed by querystring into the page. The querystring parm is useful for bookmarking the exact product to be displayed on the page and returning to it later. If people click on a "go to next item in item category" button on this page, they get the next item in the category displayed and the URL querystring item parm changes to that item number. I accomplish this with a Response.Redirect to the same page with the new querystring parm value, but I can't seem to do this with an Ajax setup because the redirect loads the page over again.

How do I keep the benefits of Ajax by having a client side refresh without reloading the page and alter the querystring to the new product number?

what u store in the query string could also be stored in the session object & the session object could be passed as a parameter to the database.


That's a good suggestion; but the issue would be the user coming back to the page at a later point, having changed the item id on the querystring via the show next item in category button. They may wander off; close their browser; destroying the session info and then want to return to their "bookmarked" page. Even if I kept the data in the DB for retrieval and could identify that customer coming in again, how would I know which product they were after? What if they bookmarked two different products originally. I wouldn't have the querystring information under AJAX to know that. I don't think I would want to show them "last product viewed" when they come back in.


write a small procedure to evaluate the query string when the user comes back.if there is a query string, pass that to the session & databind.so in any case, whether there is a session variable or not you would be able to databind.

hello.

well, i think that's not he problem he wants to solve. what he needs to do is to change the query string so that it identifies the current product but he doesn't want to perform a navigation when changing the query string.

hum...i really don't know if you'll be able to do that...try to look at the location object, though i really think this is only ie specific


Luis,

I think you described exactly what I want to do. I can do it server side with no issue using a redirect, but client side with AJAX is a problem, even though AJAX does a great job with client side refreshes on the page!


hello.

well, the problem is that what you're trying to do is not an ajax related thing. i mean, for the browser, the query string really isn't something that you can program against. it's just an url, so i think that changing it for adding or modifying a query string parameter will force the browser to navigate to a new url. if this is not a problem to you, then simply changing thw window.location property will do what you want from the client side. however, you should note that this is the same as loading a new page in the browser...

Ajax and querystring parameter

Hi,

I am developing a new application with Ajax.

I must create a new aspx page that have two mode: "view" or "modify" and show some products based on their ID.

In not Ajax context I use the query string with parameters to change the mode and the ID of products and it is very simple. I change the query string using Response.Redirect("same page + new paramaters")

With Ajax I think to use some session variables to manage the mode of page and ID of products...

Is the correct solution?

Since the view/modify is likely tied to the authenticated user, I'd suggest use encrypted ViewState variables to store the productid and page mode. It won't expire compared to the SessionState.


Ok, but I have the necessity to pass some values (modify/view, productId) to this page.

Is the viewstate accessible between pages?

If I store an object in viewstate and then there is a redirect to a new page, is the object value accessible from new page?

Thank you.


I am using the session to tranfer object between pages and then I use the viewstate for postpack in the same page.

I have a problem.

I click in a button and in onclick method I change viewstate "mode" value from "view" to "modify"...

When in the Page_Load event I test the value of viewstate mode, it is still "view" instead of "modify". The viewState value change only on next postback...i must click two times to change page modality from view to modifiy.

How can I resolve this problem?


Ok, I have inserted the check in the Page_PreRender method and now it is working fine.

I did not remember that any code that is dependent on a control event should be put into PreRender method.


If you need to keep variable value between pages, using sessionstate is one solution, keep in mind that session will expire. You can also use database to handle temporary data storage. A new feature in ASP.NET 2.0 is the postback to another page, read this article to see if it fits what you wanted:http://msdn2.microsoft.com/en-us/library/6c3yckfw.aspx

For viewstate, it only belong to the current page. The value will not be carried over to another page.