|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm having a little bit of difficulty with a user control I have placed on a master page.
The purpose of this control is to provide the user with a textbox where they can type keywords and click on the search button, it will then query the DB and populate an internal arraylist with results, which can then be accessed by calling a method on the control. I have gotten the control to POST to SearchResults.aspx which then in Page_Load attempts to read the control by first finding it on the masterpage, and then calling the relevent methods. Code:
ASP.controls_searchcontrol_ascx searchCtl = (ASP.controls_searchcontrol_ascx)Master.FindControl("searchControl");
ArrayList searchResults = searchCtl.getSearchResults();
//code here to Response.Write results, and a count from the control with the number of results from a public int counter
The funny thing is, the control as displayed in the master page once the SearchResults.aspx page is loaded displays 2 search results found in the label under the search box meaning the control looks like it is populated with the correct data.. but when attempting to call the methods from the aspx page, the arraylist is empty and everything is as if the control has just been initialised. Is there something I am missing here? I have done about a days worth of research onto this on google but have found nothing that seems to be relevent ![]() Thanks in advance! |
|
#2
|
||||
|
||||
|
There's not much to go on, you don't show a lot of code and I don't know for sure what you're trying to accomplish.
However, I have a vague idea of what the problem might be: Remember, order is everything, and pages have their own lifecycle. Child pages and events will usually process before the MasterPage's Load event, so my guess is that your ArrayList is being populated after your child controls request data from it. Part of the reason why you might have that problem is an ineffective design: why is your child control calling FindControl on its master page in the first place? That violates basic OOP principles of modularization and loose coupling. Your child controls should be completely oblivious to the existence of their container. A while ago, I needed a control on my master page to talk directly to controls in my child pages, and I came up with this solution: http://forums.devshed.com/net-devel...ols-491448.html The code has a minor error: in my BaseControl, I wire up my events in my constructor. However, I never unwire them. I figured out later on that I needed to unwire my events in my Dispose method by calling: Code:
UserManager.OnUserLoggedIn -= UserLoggedIn; UserManager.OnUserLoggedOut -= UserLoggedOut; The code was further refined into a full-blown EventManager class that I use for handling communication between most of my controls. You could use a similar method to raise an event to your child control and pass your search results directly to your search grid instead of using FindControl. Oh, and don't use an ArrayList either. Use a typed List<> (found in System.Collections.Generic namespace) instead. Trust me, it'll make your life easier.
__________________
Baby soft, because its made from real babies. Last edited by Death Goddess : January 3rd, 2008 at 09:16 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > ASP.NET web user control on masterpage not maintaining state |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|