c# - Accessing previous value in Hashtable during page refresh -


i have hyperlink field in gridview. want store clicked value during session in hashtable hyperlink field.

protected partial class user : system.web.ui.page {         hashtable htable = new hashtable();         int htableindex = 0;         // ... } 

in page load function.

if(session["test"] != null)` {         for(int = 0 ; gvuserstatus.rows.count ; i++)      hashtable temphashtable = new hashtable();      temphashtable = session["test"] hashtable;      if(temphashtable.contains(somevalue))       {           //do      } } 

in link click event:

protected void userid_click(object sender, eventargs e) {     //logic clickedvalue     if(!htable.contains(clickedvalue))     {         htable.add(htableindex++,clickedvalue);     }     session["test"] = htable; } 

i using above code, in hash table, last clicked value getting stored, should previous value entire user session?

htableindex lose value upon postback. need store in session (or viewstate if won't need it's value on other pages)

so need add in page_load event:

if (viewstate["htableindex"] == null)     viewstate["htableindex"] = htableindex; 

and in link click event userid_click

protected void userid_click(object sender, eventargs e) {     //logic clickedvalue     if(!htable.contains(clickedvalue))     {         var htableindex = convert.toint32(viewstate["htableindex"]);         htable.add(htableindex++,clickedvalue);     }     session["test"] = htable; } 

let me know if works. haven't tested yet.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -