Last post Jun 16, 2009 03:22 PM by rmdw
Jun 16, 2009 02:21 PM|rmdw|LINK
I'm following up on a previous post but targeting in where I now think the problem lies. Here's my situation:
I have an ASP.Net 3.5 web project written in C#. I am trying to introduce a toolbar which is implemented as follows:
I've constructed things in such a way that I can customize the names & images of each toolbar button. So, for example, one Content Page may display these toolbar buttons: Add Edit Move Save. While another Content Page may display these toolbar buttons:
Insert Delete Save. Any combination of the known button types is permissible.
As you're probably envisioning, the toolbar buttons are instantiated dynamically, depending on what parameters are passed to the 'CreateCommandButtons' method within the User Control.
Everything is working fine except for one crucial thing: When I change the enabled/disabled setting of each toolbar button, the value is not remembered after a postback; in my particular case, it's a partial postback on an AJAX enabled page.
So I went back to basics and decided to simulate the same approach in a small test project, which you can download here: http://mwtech.com/downloads/public/Dynamic_Button_Creator.zip
Here's what you need to do:
So to my great surprise, the test project works fine!! Yet very similar code within my actual project is not working. Instead, there, when you execute Step #4 above, the center button would revert back to gray.
So I did more reading and it seems that it's the IPostBackDataHandler interface that is responsible for restoring the altered control values. Yet it's not doing this in my real project I'm hoping that someone familiar with IPostBackDataHandler can tell
me what key things to look for to see why it's not functioning properly.
Jun 16, 2009 03:22 PM|rmdw|LINK
After about 5 hours of scratching my head on this, I finally found a solution ... though I don't know why it works!
I've long followed the practice of setting: EnableViewState="false" on any page which I didn't feel needed ViewState. This seemed to be a good practice.
And in the case of IPostBackDataHandler, articles like this one seemed to confirm that it was fine to turn off the View State: http://www.codeproject.com/KB/viewstate/ViewState.aspx
Yet when I noticed that my test Content Page had EnableViewState="false" I set it to true and ... voila, suddenly my User Control toolbar had its changed values restored once again!
Then I set EnableViewState back to false in the Content Page and explicitly set it to true in the User Control. It did not work.
So there's a bit of a mystery here. Certainly I have things working now but I would love to hear from a State Management guru as to why things are occurring as they are!