![]() |
| ||
| Wizard Control with User Control This problem has got me scratching my head. I have an ASP .NET wizard control. Within the step view, I put a user control. The user control contains a FormView. The Formview contains a mixture of standard ASP .NET controls and other user controls. In one situation, I have two user controls containing a dropdown list control. I set up an event to fire if the selectedindex of the first dropdown list control changes (which is set to AutoPostback), and the wizard control subscribes to this event. In the event handler of the wizard control, if the first dropdown has a certain value, I want to disable the dropdown in the second user control. So I set up something like this: private void MyEventHandler(object sender, myeventargs e) Here's the problem. I can't disable the second dropdown. The second dropdown remains enabled. Now, if I try to disable the second dropdown when the NextButtonClick event fires when moving from the previous wizard stop, using similar code as above, I have no problem. Using FindControl, I can get the dropdown I need to disable it. But when I do this after the controls have been rendered in the step, I can't disable the dropdown on a postback, I can't set it as invisible, I can't change the background color, etc. I don't know why this is the case. I've tried a number of things to get this to work including:
As an experiment, I added a dropdown to the view of another wizard step, setting it to autopostback, and in the selectedindex change event disabling the dropdown. This works! So in my situation, either I'm not getting the correct dropdown to disable, or the fact that it is embedded in a user control is not allowing changes once the control is rendered, or the control is being reinitialized (which I don't think it is because the first dropdown retains the "The Value I Want" value I selected instead of a default value). Can someone explain why I can disable a dropdown in a usercontrol when moving from a previous wizard step, but I can't disable the dropdown in the postback of the step where I need to disable it, yet I can disable a dropdown in a step postback if the dropdown is an immediate child control of the wizard control (that is to say, not part of a usercontrol, formview, etc.)? |
| ||
| Re: Wizard Control with User Control I tried something else. I added a new dropdown to the wizard control step, outside of any existing user control in the wizard view (so this dropdown is an immediate child control of the wizard control, not embedded in a user control ), put in two items ("yes", "no"), and set autopostback to true. First, I tried to disable this new dropdown at the same place I'm trying to disable the other dropdowns; in the event I set up in my example (this event is fired when the selectedindex changes for a dropdown in another usercontrol). I couldn't disable my test dropdown. Then I set up a selected index change event handler for this new dropdown in the wizard control code behind and tried to disable the dropdown there. This worked!! So maybe my problem has nothing to do with where the dropdownlist control is located (standalone or within a user control), and everything to do with where I'm trying to disable the controls. Just a guess, but maybe the wizard control isn't doing a postback in the event I created. When the first dropdown (the one I need to look at for the value) does it's selectedindexchange postback, it posts back to the user control that contains it, then fires off the event I created that then gets handled in the wizard control. Even though I'm handling the event, and even though I can step through the event's code behind, maybe the wizard control isn't doing a postback when handling the event I created. When I make the change capture the selectedindexchanged event for the new dropdown, the wizard control does do a postback based on the dropdown's autopostback property. Anyone have any ideas about this, and ideas how I can get this to work? |
| ||
| Re: Wizard Control with User Control Oh, I forgot to mention that I put a breakpoint in wizard control Page_Load and examined Page.IsPostBack. When the wizard control handles the event I set up, Page.IsPostBack is true. |
| ||
| Re: Wizard Control with User Control Two more clues: I looked at two dropdownlist properties while debugging.
What I found is:
I'm finding very little information about these two non-public fields other then some information about setting _pagePreLoadFired an accordion Ajax control and some databinding requirements in OnPagePreLoad. Can anyone tell me if and why this is significant, if it could be a clue to the problems I'm having, and a suggested workaround? |
| ||
| Re: Wizard Control with User Control Now I have even more clues. I enabled trace and put out a Trace.Warn message before and after I try to disable the dropdownlists that I haven't been able to disable (dropdownlist is part of a user control, an event handler is set up in wizard control that gets fired when the dropdown's selectedindex event is handled in the user control). Here is the trace information (I've edited out the time information): aspx.page Begin PreInit All that is available is a Trace.Warn message I put in Page Load. Now here is the trace information for the other dropdownlist scenario I have (autopostback, not part of a user control, selectedindexchanged event handled in the wizard control). aspx.page Begin PreInit So it looks like I haven't been able to disable some dropdownlists because everything has already been loaded and rendered. It seems that the event handler I created gets processed too late in the page cycle to make any control changes in code. Does anyone know how I can correct this? |
| ||
| Re: Wizard Control with User Control Now I have even more clues. I was mistaken when I said that my dropdownlist disable wasn't working in my event handler because "everything has already been loaded and rendered". What was really happening was that my Trace.Warn message in that event handler wasn't being written to the log. I'm not sure why, but I looked at a trace private variable called Trace._endDataCollected and it was true. At other points in the application (points where Trace.Warn messages were being written to the log), it was false. Very strange. I'm not sure at what point trace information collection ended. I was also able to determine that my event handler fired before the RaisePostBackEvent event, but I'm not sure if it fired before the end of RaisePostDataChangedEvent. I spent some time reading this article on page life cycle (http://www.15seconds.com/issue/020102.htm) and looked through the example code to figure out a workaround! Instead of depending on an event handler fired by a selected index change in a user control, I put something like this in the OnLoad method:
Doing things this way disables the dropdownlist that I need to disable! I'm still not sure why trying to disable the dropdownlist control in the event handler didn't work, nor am I sure why Trace._endDataCollected was set to true by the time processing got to the event handler, but at least I got something to work. I'd still like to know exactly where in the page life cycle the event handler is fired but, since I couldn't do an override of RaisePostDataChangedEvent, I can only guess. If anyone has any ideas on how I can debug this further, please let me know. |
| ||
| Re: Wizard Control with User Control The plot gets thicker. I put a Trace.Warn message in my first user control (which has a dropdownlist set to autopostback) in the selectedindexchanged event handler of the dropdownlist. aspx.page Begin PreInit It looks like the first dropdownlist selectedindexchanged event is happening within the RaiseChangedEvents. I fire off an event at this point, which gets handled in the wizard control, at which point I try to disable a second dropdownlist. As mentioned previously, I can't disable the second dropdownlist here, a Trace.Warn message in this event doesn't write to the log, etc. My guess is that the wizard control only sees the first dropdownlist autopostback as a "changed" event. By the time I try to disable the second dropdownlist in the event handler in the wizard control, the page life cycle has already loaded viewstate to the second dropdownlist and doesn't recognize the code behind disable control as a change. As mentioned in the article I linked to "each control is flagged with a Boolean on whether its data was actually changed or remains the same since the previous submit." The first dropdownlist is flagged but when trying to disable the second dropdownlist in the event handler in the wizard control, it is too late in the page life cycle for it to be flagged as a change. This is only a guess, of course, and doesn't explain why, if two dropdownlist controls are immediate child controls of the wizard control, you can put in a selectedindexchanged event for one dropdownlist and still be able to disable a second dropdownlist. After all, the "changed" control is the first dropdownlist, and disabling the second dropdownlist control should happen at the same point in the page life cycle. I'm still baffled by this. |
| ||
| Re: Wizard Control with User Control 1 Attachment(s) I'm still not able to figure out this problem. Maybe a "picture" will be worth a thousand words. I've attached a zip file that contains a sample program that functions similarly to the application I'm having problems with. Default.aspx.cs contains two methods: Page_Load and an event handler. Page_Load contains the event subscription for Dropdown1 change index. It also contains commented out code that looks at the selected value of Dropdown1 and disables Dropdown2 if the value is "Yes." This block of code works when uncommented. Dropdown 2 is disabled. The event handler also attempts to disable Dropdown2. If the event argument (the selected value of Dropdown1) is "Yes," Dropdown2 is disabled. Only it isn't. And that's the problem. I can't figure out why I can't disable the second dropdown here. If I try to do something like change the background color of Dropdown2, that also doesn't work. And, as I mentioned before, if I put a Trace.Warn message in this method, it doesn't get written to the trace log. You can step through the code in debugger but some things don't seem to work. The rest of the code is various user controls and event classes. Let me know if you find something I haven't found. |
| All times are GMT -4. The time now is 3:57 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC