Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Tough Q on Dynamically adding cached User Controls

Reply
Thread Tools

Tough Q on Dynamically adding cached User Controls

 
 
Justin Dutoit
Guest
Posts: n/a
 
      03-19-2008
Hi folks. I have a question on using LoadControl to dynamically add user
controls to a page. The relevant URL is

http://www.quickshopdemo.com/Product...2cmilk%2cjuice

.... and the code is below (refresh the page straightaway to see the
problem). The page is a multiple search page, which takes several search
terms and assigns one to each user control. The user control does a fairly
simple search on Brand and Productname. The idea is that by having several
simple user controls, caching could be used on each user control, for a
faster web page.

However, what happens is that, when the user controls are taken from the
cache, the last search term is applied to all the user controls- e.g. search
on bread, milk and juice, and get 'juice' for all the user controls. I am
new to this sort of caching- I'd appreciate it if someone could see what
might be wrong with my code.

Thanks a lot!

Justin.

Code follows:

SearchItems = Utilities.ExtractSearchItems(Request.Params("Multi pleSearch"))

' The BrandSearchString inside this for loop are the capitalised words. The
regular SearchString are lowercase words

For Counter = 0 To SearchItems.Count - 1

BrandTerms = ""

NameTerms = ""

Dim WordsInThisSearch() As String = Split(SearchItems(Counter), " ")

DoSeparateBrandandProductNameWords(WordsInThisSear ch, BrandTerms, NameTerms)


'************************************************* ************************

' Dynamically add Search user control, allowing for a cached user control

'************************************************* ************************


Dim ctlNextSearch As Control = LoadControl("SearchCBPicsCacheV1.ascx")

MyPlaceHolder.Controls.Add(ctlNextSearch) ' mySearchControl

Dim mySearchControl As SearchControl = Nothing


' i.e. If the search user control exists (not in the cache)

If TypeOf ctlNextSearch Is SearchControl Then


mySearchControl = CType(ctlNextSearch, SearchControl)

Response.Write("Is sc<BR />")

' i.e. if the user control is cached

ElseIf TypeOf ctlNextSearch Is PartialCachingControl And _

Not CType(ctlNextSearch, PartialCachingControl).CachedControl Is Nothing
Then

mySearchControl = CType(CType(ctlNextSearch,
PartialCachingControl).CachedControl, SearchControl)

Response.Write("Is pcc- BrandTerms=" & BrandTerms & ", NameTerms=" &
NameTerms & ".<BR />")


ElseIf TypeOf ctlNextSearch Is PartialCachingControl And _

CType(ctlNextSearch, PartialCachingControl).CachedControl Is Nothing Then

Response.Write("pcc.cachedcontrol Is Nothing- uc came from cache<br>")

If mySearchControl Is Nothing Then

Response.Write("mySearchControl Is Nothing<BR>")

Else

Response.Write("mySearchControl Is Not Nothing<BR>")

End If

Response.Write("From Cache- BrandTerms=" & BrandTerms & ", NameTerms=" &
NameTerms & ".<BR />")

' when this happens, the last search item is copied over all the items, i.e.
Bickford's

' which is the last search item, is in every search result

End If


' Now we have mySearchControl which we can use regardless of cache or no
cache

If Not mySearchControl Is Nothing Then

mySearchControl.SearchString = NameTerms

mySearchControl.BrandSearchString = BrandTerms

mySearchControl.SearchNumberForNext = Counter

mySearchControl.LastSearchNumber = SearchItems.Count - 1


End If


Next


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tough Question: Accessing controls inside inline template in a user control, in a repeater Dave ASP .Net 1 12-22-2006 12:58 PM
my cached dataset just wont stay cached!! Craig G ASP .Net 0 03-07-2005 10:02 AM
Efficiency of dynamically adding web user controls MC D ASP .Net 4 11-18-2003 07:27 PM
Cached User Controls Steve ASP .Net 1 07-07-2003 01:44 PM
Cached User Controls Steve ASP .Net Web Controls 0 07-07-2003 01:35 PM



Advertisments