0

As the itemcommand event fires after most if not all page/control init/load events. what is the best way to persist session variable data that is modified on itemcomment (adding items for example) so that the page can react to the itemcommand using the modified session?

kbrimington
  • 25,142
  • 5
  • 62
  • 74
Skowronek
  • 308
  • 3
  • 10
  • Only solution I see (and works) is to handle whatever functionality on prerender of the page. Appears to work, but odd the itemcommand doesn't fire as other control events do. – Skowronek Aug 06 '10 at 19:08
  • 1
    Can you provide an example of what you're trying to do and what's not working for you? In general you should be able to modify the session as you see fit in the itemcommand handler, but since most of the page events have already fired your page won't reflect any of these changes until the next request (which usually isn't what you want). – Stefan Mohr Aug 06 '10 at 19:35
  • The problem was I needed a counter to update on the page after a button was clicked in the listview. I was able to accomplish by throwing the update logic into the page prerender event. – Skowronek Aug 07 '10 at 15:51

1 Answers1

0

You could catch the postback earlier in the page's lifecycle:

// id of the control
   string id = Request.Form["__EVENTTARGET"];  

   if (!string.IsNullOrEmpty(id) && id.Contains("myControlId"))  
   {
        string argument = Request.Form["__EVENTARGUMENT"];
        ...
   }

but it's neither very elegant nor safe. I would follow the suggestion of Skowronek: to put more logic on PreRender.

onof
  • 17,167
  • 7
  • 49
  • 85