.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 3rd, 2008, 04:35 AM
daniel.byrne daniel.byrne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 6 daniel.byrne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 39 sec
Reputation Power: 0
Cool ASP.NET web user control on masterpage not maintaining state

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!

Reply With Quote
  #2  
Old January 3rd, 2008, 09:14 AM
Death Goddess's Avatar
Death Goddess Death Goddess is offline
Crushing a million faces
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 282 Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level)Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level)Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level)Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level)Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level)Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level)Death Goddess User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 11 h 25 m 14 sec
Reputation Power: 89
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > ASP.NET web user control on masterpage not maintaining state


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT