About 5 months ago I was tasked with creating a new intranet site for my current employer as the old one is a nightmare to work with. The site uses multiple .NET
languages (classic asp
, VB
, and C#
) with multiple .NET frameworks
(1.0, 2.0, 3.5, few places with 4.0). Simple changes that should only take an hour to implement and test would take days just to implement.
The new intranet sites content is controlled through user controls that are loaded dynamically at load time based on the page you are on and the access level you have. Each user control has a specific task and does not affect any other user control on the page.
About 3 weeks ago my database guy (was an application developer at his last job) pitched this idea to the middle management that the user controls could talk to each other and affect the selections available in each user control (all this without my knowledge).
At first, I didn't think it was possible when I heard. Then, everything I read about having user controls communicate with each other indicated that the user controls had to know about each other and that wasn't possible since all of the user controls are load at runtime based off of the access level you have. I found a solution last week were I could have a user control fire a custom event handler and have my other user controls listen for that specific custom event handler.
Now, today, I was asked if I could add filtering to the contact management part of the site that lists all of our clients similar to how Ebay has there filters on the left that allows you to drill down farther into the results returned. For example, you search "flat screen tvs". Ebay will list all results that match you search and on the left you can select the size range or the brands to narrow down the results.
On the page I setup I load 3 user controls to handle the criteria and the results. Control1
has all of the basic search criteria (ex. industry, region state, ect), control2
has the filters for drilling down the results from control1
. Control3
displays the clients based off the criteria in control1 (so control1 fires an event that control2
and control3
hear and they both display the results based on control1). Now I select the criteria from control2
and fire the event that control3
can hear and displays the results.
All of this works, the problem I am having is that the controls in control2
are built dynamically and when the event in control1
is fired -> then control2
posts back to fire the event for control3
to hear I lose all the dynamic controls in control2
as the controls can't be recreated in the Page_Init
because the values passed in from the custom event in control1 no longer exists because control2
did the postback and the event from control1
is only fired when control1 postsback. What is the best way to store the values passed in to control2
from control1
's custom event or get control1
to repass the values when control2
posts-back so I can recreate the dynamic controls in control2
?
Note: I tried using sessions but had trouble reassigning values from control1 after the first search. I believe the reason they don't work is due to the way I have control1 setup and the creation of dynamic controls in control2
is skipping over getting the session values.
I thank all of you in advance for your (hopefully) helpful responses.
Update
Turns out that the way I was loading my usercontrols at runtime on my default page is the reason why the dynamic control in 'control2' were not being recreated when 'control2' posted back. My default page loaded the usercontrols in the 'page_load' instead of the 'page_init' (must have forgot to move the loading of usercontrol to the 'page_init' like all my other pages). Made the switch and the dynamic controls are recreated on postback.
The only issue that I had after moving my code from the 'page_load' to the 'page_init' was that the 'checkbox' controls would be unchecked on postback even though I checked them. I was able to over come this with a few session variables.