Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   User Control to Control Other User Control (http://www.velocityreviews.com/forums/t712764-user-control-to-control-other-user-control.html)

Jonathan Wood 01-24-2010 04:58 PM

User Control to Control Other User Control
 
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



Gregory A. Beamer 01-24-2010 07:46 PM

Re: User Control to Control Other User Control
 


"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:uQ5stZRnKHA.1552@TK2MSFTNGP05.phx.gbl...
> 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.


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://gregorybeamer.spaces.live.com

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


Jonathan Wood 01-25-2010 04:40 PM

Re: User Control to Control Other User Control
 
Gregory A. Beamer wrote:

> 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


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.

> 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.


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.

> 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?


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



Gregory A. Beamer 02-01-2010 05:27 PM

Re: User Control to Control Other User Control
 


"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:uYAPk0dnKHA.1548@TK2MSFTNGP02.phx.gbl...
> Gregory A. Beamer wrote:
>
>> 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

>
> 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.
>
>> 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.

>
> 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.
>
>> 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?

>
> 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.


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! |
************************************************


Jonathan Wood 02-02-2010 03:41 PM

Re: User Control to Control Other User Control
 
Gregory A. Beamer wrote:

> 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.


The number of controls is fixed.

> 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.


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.

> 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.


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.

> 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'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 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.


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

Thanks.

Jonathan




All times are GMT. The time now is 09:16 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.