User Control to Control Other User Control

User Control to Control Other User Control

Post by Jonathan W » Tue, 26 Jan 2010 01:58:10


Has anyone here created a control that controlled the content of other
controls?

I have my own custom ad control (for displaying space ads). I may have
several on a page. What I'd like it to create another control that could
determine how many instances of the first control existed on the current
page, build a list of ads, and then set each control to show a particular
ad.

Is this practical? Suggestions?

Thanks.

Jonathan
 
 
 

User Control to Control Other User Control

Post by Gregory A. » Tue, 26 Jan 2010 04:46:17


Step back from the problem for a second. Here is what it sounds like you are
saying.

1. I have randomly created ads, so I have no clue how many are on a page
2. I want a control to find these random controls and then make a list of
their ads
3. I then want this control to fill these ads

Now, unless you are refilling controls on the client side, you will know
what is in the controls. If so, you might create some JavaScript to flip
them out, but you should still output (emit) this client script from the
server, where you still have control.

As such, I see no reason to have a control to monitor other controls.
Instead, I see a control you send a full list to as you fill the individual
controls. Perhaps you also have some emited script to change the ads and
update the controller control. But since this is merely JavaScript, I see no
reason to have a "control" per se. Make sense?

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://www.yqcomputer.com/

************************************************
| Think outside the box! |
************************************************

 
 
 

User Control to Control Other User Control

Post by Jonathan W » Wed, 27 Jan 2010 01:40:36


1. I know how many ads are on a page; however, control instances do not know
how many other instances there are.
2+3. Something like that.


I'm not sure how that would work. Just to clarify, I don't know if I used
the term "a control to monitor other controls" but all I really mean is a
separate control to coordinate things. Exactly how that is accomplished is
what I'm asking.


The ads are coming from my database so really there's no no client-script
involved.

For me the, issues are A) I suspect it is less efficient to have multiple
controls hit the database than to hit the database once for all controls on
a page, and B) when separate controls hit the database separately, I can get
duplicate ads on different controls.

Thanks.

Jonathan
 
 
 

User Control to Control Other User Control

Post by Gregory A. » Wed, 03 Feb 2010 02:27:16


"Jonathan Wood" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...

Since everything is coming from the database, grab the list of ads and make
sure they are filtered to the number you want on the page. Then dynamically
instantiate the proper number of controls.

If this does not work, I would suggest iterating through the controls and
finding all ad controls. If you truly have an "ad" control, it will be easy.
If it is merely an image link type of object, you will need naming
convention on top to ensure you only grab ad images. If you want a count
before grabbing ads, you can either

a) iterate back through when you are adding ads (since the number is low,
iterating is fine)
b) store in a collection and then iterate through the collection (this is
only a benefit if the number of ads on a single page is ridiculous or there
are huge numbers of images, as the cost of instantiating the collection will
be heavier than iteration through images again). It is conceptually cleaner,
however, to go through only once, so it is not a bad pattern, but understand
you may negatively impact performance (in the milliseconds range) for the
added "beauty" in the code.

Once you know your objects and ads, just start feeding. If you are using
postbacks, you can update on a postback. If you want to use AJAX to reset
the list, you can do that as well, although you have to think through the
problem a bit more.

If you need to rotate the ads, set up the JavaScript to swap out images and
HREFS from a list or lists before sending to the client. This is a bit more
complex, but there are libraries out there that can help you if you google
for JavaScript image libraries. I tend to look at JQuery first, but I am not
sure if it has any functionality for anything like this. My reason is
twofold:

1. I use it a lot and it has a lot of bang for the buck
2. Microsoft is putting full support for JQuery in the 4.0 timeframe.

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
| Think outside the box! |
************************************************

 
 
 

User Control to Control Other User Control

Post by Jonathan W » Thu, 04 Feb 2010 00:41:10


The number of controls is fixed.


Right, this is where I've been looking. (I do truly have an "ad" control.)

I guess I was wondering if this was the most efficient way to locate the
other controls. So I was thinking about maybe adding a property that
contains a list of the other control IDs. But perhaps I should do as you
suggest and not worry about performance.


Okay, I would've thought it would've been faster to create a collection that
scanning the page for controls multiple times. That's helpful if I was
backwards on that. Perhaps I should even do a bit of profiling of this.


I'm not certain what sort of rotating you had in mind. I'm pulling the ads
from a database in a somewhat random fashion. If the page reloads, I would
just do it again. I guess I could look at just having the "ad" controls keep
their ad markup in viewstate and then not access the database again for
postbacks.


I haven't looked into that. Is that in the current VS 2010 beta?

Thanks.

Jonathan