Passing databetween user controls

D

Dranreb

Hello,

I use a template whereby my default page contains various user controls -
i.e. "Header", "Footer", "Navigation", "Content".

On some occaisions I'd like to manipulate the other controls from the
content control, without refreshing the default page. Currently, to change
the content I refresh the default page by doing a response.redirect and
referencing the new content page in the querystring. My default page
includes the following in its postback:
Dim p As String

p = Request.QueryString("Page")

If p = "" Then

With phContent

..Controls.Clear()

..Controls.Add(LoadControl("Home.ascx"))

End With

Else

With phContent

..Controls.Clear()

..Controls.Add(LoadControl("~/Protected/" & p & ".ascx"))

End With

End If

Is their an easier way to do this without having to refresh the aspx page,
for instane content changes header, or navigation updates footer, etc.?

Thanks in advance,

bw
 
B

billmiami2

I'm not entirely clear on your situation. However, it seems to me that
your problem might be solved simply by defining some custom events on
your user controls. For example, you could have an event fire every
time control A was changed in some way. This event would be trapped
and handled on the page and would cause properties to be set or methods
to be called in controls B, C, D, etc.

For example, in user control A:

'Declare the event
Public Event SomethingChanged (ByVal obj As Object, ByVal e As
EventArgs)

'Raise the event inside a property or method in the control
RaiseEvent SomethingChanged (EventArgs.Empty)

Inside the page, trap the event and do something to the other controls
as a result

Sub ControlAChanged (obj as Object, e as EventArgs) handles
controla.SomethingChanged
'set properties or do something to other controls in the page
End Sub

Using events should allow you to coordinate the controls within the
page without resorting to Response.Redirect. Of course, this still
happens within the context of a postback. If you want controls to be
changed without any postback, you'll need to do that on the client side
with javascript.

Bill E.
 
D

Dranreb

I'll try it but it appears that I would be updating controls on the existing
acsx page. What I want is to change the controls on another acsx page
without affecting the aspx page at all.

Thanks, I'll let you know how it works out.
 
B

BW

Resolved the issue. Here's how:
Even during the problem I could always find the PlaceHolderControl -
"phHeader" on the Page object. Once I found it, I just traversed every
control it contained until I came accross the controls, in this case labels,
I was searching for.

Code:
===========================================================================
===========================================================================
Dim ph As PlaceHolder = Page.FindControl("aiHeader")

Dim c As Control

For Each c In ph.Controls

If TypeOf c Is aiHeader Then

Dim cLabel As Label

cLabel = c.FindControl("lblProjectName")

cLabel.Text = sProject

Session("ProjectName") = cLabel.Text

Dim sUser As Label

sUser = c.FindControl("lblUserName")

sUser.Text = Page.User.Identity.Name

End If

Next

====================================================================================================

====================================================================================================

This works for me. I'm not sure what kind of perfomance hit I take, but this
isn't a high volume site anyway.

Thanks for your suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top