473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Keeping 2 user controls of the same class synced

On a page, I need to show one item at a time. The top of the page has a
Previous-Next control, followed by the item being shown, followed by
another Previous-Next control. I have created a P-N user control and
customized it to fire an event, OnChange, when a Previous or Next
button is clicked, which is handled by the containing page. The handler
takes the ID of the current item from the eventargs and displays the
proper item with the ID in the center. But In addition, I want the
other P-N control also to reach the same state as the one that fired
the event. So the CurrentID property of both the P-N controls would be
the same.
Any design suggestions?

Thanks,
Yash

Dec 15 '06 #1
2 1050
Hi,

ya****@gmail.com wrote:
On a page, I need to show one item at a time. The top of the page has a
Previous-Next control, followed by the item being shown, followed by
another Previous-Next control. I have created a P-N user control and
customized it to fire an event, OnChange, when a Previous or Next
button is clicked, which is handled by the containing page. The handler
takes the ID of the current item from the eventargs and displays the
proper item with the ID in the center. But In addition, I want the
other P-N control also to reach the same state as the one that fired
the event. So the CurrentID property of both the P-N controls would be
the same.
Any design suggestions?

Thanks,
Yash
Since your user control fires an event OnChange, have the other user
control register that very event. Of course, that means that the target
user control must have knowledge of the event's definition, but that's
the case anyway since both are of the same class (as per your subject line).

Other ways would be using a listener pattern, having the target UC
register at the source UC for changes. When a change occurs, the source
UC loops through all the registered listeners and calls a method on
them. The method is defined in an interface IListener (or whatever ;-),
which introduces only a loose relationship between the two user controls.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 15 '06 #2
Other ways would be using a listener pattern, having the target UC
register at the source UC for changes. When a change occurs, the source UC
loops through all the registered listeners and calls a method on
That's what precisely the multicast-delegates and events are!
Well, if you publish an event and somebody subscribes to it, it IS the
listener pattern. You don't need to have IListener. :)
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
Jan 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Babu Mannaravalappil | last post by:
My Windows application (C#) has a login screen and a user table to handle user rights and accessibility. This is independant of the OS level user security. At the time of launching the...
9
by: Alfred Taylor | last post by:
I'm testing the waters of n-tier development and I ran into a scenario that I'm not sure what the best solution would be. I have a Company object which contains a collection of contacts retrieved...
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
3
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
0
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
7
by: David Lozzi | last post by:
Howdy, I have a usercontrol in my aspx page and when the page loads, I send it some property values based on the data displayed. I am sending it to a public property like below. However the...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
3
by: Fred Chateau | last post by:
I am trying to access a user control class, for a user control that is loaded dynamically, from the containing page. I have been able to access Web controls in the user control, but so far I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.