469,575 Members | 1,662 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Access ASCX properties/methods from another ASCX file

i know you can access an ascx's properties/methods from an aspx file.
Let's say you have an aspx file with two code-behind files(ascx files).
Can you access one of the ascx file's properties/methods from the other
ascx file?

Nov 19 '05 #1
5 2802
<dj****************@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
i know you can access an ascx's properties/methods from an aspx file.
Let's say you have an aspx file with two code-behind files(ascx files).
Can you access one of the ascx file's properties/methods from the other
ascx file?


You could, if the other .ascx file knew that the first one was there. But
why should it know that the other one is there?

You should try to make your user controls independant of each other, so that
they can be used in various combinations. You should allow the page that the
user controls are on to mediate between them (this is similar to the
Mediator Pattern). Have the user controls expose properties and events. The
page can set and read the properties, and can respond to the events.
Certainly, the page could set a property in one control based on the value
of a property in another control.

This way, each user control just does its own thing, and coordination for a
particular purpose is performed by the page.

The only exception to this is when you have a set of user controls which are
frequently used together to perform the same task. The solution is to create
a user control to contain this set of user controls. Let the container user
control be the Mediator of the controls it contains. The container might
have properties and events which were originally the properties and events
of its contained controls, but that's just fine:

Container.ascx.vb:

Protected WithEvents _innerControlA As InnerControlA

Public Property Username As String
Get
Return _innerControlA.Username
End Get
Set(ByVal Value As String)
_innerControlA.Username = Value
End Set
End Property

This way, the individual user controls in the Container are still
independant of each other, and one won't have to be changed if the other
changes. Only the Container would have to change, and the Page itself might
not even have to change.

John Saunders
Nov 19 '05 #2
dj****************@yahoo.com wrote:
i know you can access an ascx's properties/methods from an aspx file.
Let's say you have an aspx file with two code-behind files(ascx files).
Can you access one of the ascx file's properties/methods from the other
ascx file?

I don't see why not if you have a reference to the instances of classes in
the files
Nov 19 '05 #3
Sent an event or grab an interface:
http://www.openmymind.net/communication/index.html

S. L.

<dj****************@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
i know you can access an ascx's properties/methods from an aspx file.
Let's say you have an aspx file with two code-behind files(ascx files).
Can you access one of the ascx file's properties/methods from the other
ascx file?

Nov 19 '05 #4

thanks for all of the help. i'll read the tutorial information. im sure
that will help.
im new to asp.net development. most of the stuff ive done is in asp.
i guess what im trying to do have a main aspx page with a few ascx
files (code-behind). Ascx A is where the user enters information. Ascx
B displays the results based upon the info entered into ascx A.
thanks again for the good leads. any assistance is always appreciated.

Nov 19 '05 #5

thanks for all of the help. i'll read the tutorial information. im sure
that will help.
im new to asp.net development. most of the stuff ive done is in asp.
i guess what im trying to do have a main aspx page with a few ascx
files (code-behind). Ascx A is where the user enters information. Ascx
B displays the results based upon the info entered into ascx A.
thanks again for the good leads. any assistance is always appreciated.

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by paul meaney | last post: by
6 posts views Thread by William Parker | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.