Saturday, March 24, 2012

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.

No comments:

Post a Comment