c# - Passing session variable from one page to another -



c# - Passing session variable from one page to another -

i've done php while back, , want c#. think might on right track going wrong along way.

what have "create order" page, contains basket of items user purchase. on page, can search products name or sku, , grid view of results displayed if typed in valid. can navigate add/update page can either add together new product basket or edit/update 1 there. takes them basket page.

on "create order" page, setting session variable cart id based on whether cart id found in url query string:

protected void createsessionvariable() { string session = ""; if (request.querystring["cartid"] != "" & request.querystring["cartid"] != null) { session = request.querystring["cartid"]; session["cartvalue"] = session; } else session["cartvalue"] = ""; }

i calling page_load function:

if (!page.ispostback) { bindbasketgrid(); //call function if (session["cartvalue"] != "" & session["cartvalue"] != null) { string cartcode = request.querystring["cartid"]; cartidlbl.visible = true; cartidlbl.text += cartcode; } else createsessionvariable(); }

in add/update page's page_load, calling (and called within !page.ispostback:

if (session["cartvalue"] != "" & session["cartvalue"] != null) { string cartcode = session["cartvalue"].tostring(); cartidlbl.visible = true; cartidlbl.text += cartcode; }

things work little while--the session variable passed "create order" page add/update page successfully. but, when returning create order page, session variable no longer set.

am setting things incorrectly?

the & using makes status session["cartvalue"] != "" & session["cartvalue"] != null bitwise and.

in c#, need && and:

if (session["cartvalue"] != "" && session["cartvalue"] != null

this statement can written easier this:

string s = session["cartvalue"] string; if (!string.isnullorempty(s))

c# asp.net session

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -