So first he checks if there is a viewstate, there is no viewstate.
He makes a new Unique ID, and he checks if there is a product id and a count.
If its there he adds it to the database.
But if i come back on this page, the ViewState is gone...
Is the methode i use nog ok ?
I thought the viewstate is available till you close the browser ?
hi, ViewState is available till the time you are in the same page. if you redirect to other page and then once again come back to that page ViewState will loose the value it have. you can use something like session/cookie to store the value depending upon the
security parameters. Thanks,
Jelmer850i
Member
232 Points
1053 Posts
Using ViewState for a ShoppingCard?
Mar 18, 2009 11:23 AM|LINK
Hi, i'm bulding a webshop.
Right now the products are in the webshop but i need to add some to the shopping card.
It should be possible to fill the webhop without loggin in in the webshop.
So i thought, using ViewState.
And build this:
protected void Page_Load(object sender, EventArgs e) { try { //Get ViewState if (ViewState["ShoppingCardID"] == null) ViewState["ShoppingCardID"] = CreateShoppingCardID(); if ((Request.QueryString["productid"] != null) && (Request.QueryString["aantal"] != null)) { //Add Item to shoppingcard int ProductID = int.Parse(Request.QueryString["productid"]); int Count = int.Parse(Request.QueryString["aantal"]); addItem(ProductID, Count); } Bind(); } catch (Exception ex) { lblError.Text = ex.ToString(); lblError.Visible = true; } } protected void Bind() { repWinkelwagentje.DataSource = webshop.getShoppingCard(ViewState["ShoppingCardID"].ToString()); repWinkelwagentje.DataBind(); } protected void addItem(int ProductID, int Count) { webshop.AddShoppingCard(ViewState["ShoppingCardID"].ToString(), ProductID, Count); }So first he checks if there is a viewstate, there is no viewstate.
He makes a new Unique ID, and he checks if there is a product id and a count.
If its there he adds it to the database.
But if i come back on this page, the ViewState is gone...
Is the methode i use nog ok ?
I thought the viewstate is available till you close the browser ?
arvind.kango...
Member
62 Points
11 Posts
Re: Using ViewState for a ShoppingCard?
Mar 18, 2009 12:22 PM|LINK
view state
Ramp Technology Group.
Jelmer850i
Member
232 Points
1053 Posts
Re: Using ViewState for a ShoppingCard?
Mar 18, 2009 12:47 PM|LINK
Ok! is that it.
I go using sessions thnx