View Single Post
Old June 30th, 2005, 04:23 AM
dhmderuiter dhmderuiter is offline
Registered User
Join Date: Jun 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Peter, thanks a lot for helping out.

Basically what I'm trying to achieve is this:
I have a set of pages and they all use the same user controls named top, menu and bottom. Menu is only showed in the pages if a user has logged in. The user control top is the one that matters, there I like to set a lot of variables/properties for the pages to use. For example a userID, so I don't have to retrieve it in every page trough queries and all, but can ask it from the user control.

A lot is basically interaction from user control to page, like userID, viewmode, usergroup, etc. I set these values in the user control, I use them both in the usercontrol and in the page. Some of the values I also want to user in the menu user control. From the page I only set one value in the user control being systempageID (which tells the user control which page it's handling, I guess that's bad, but I need it for knowing some variables for display).

At this moment I think the public properties are an easy way to handle such stuff, but I'm not sure. Consering the second answer you gave, I guess I'm already doing that:

Public Class Home
  Public Top

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Top.Systempage = "2"
  End Sub

End Class

Top_Load in the Top user control does:

Public Sub Top_Load()
  '## Maintenance check

  '## No cache
  Response.Cache.SetCacheability(HttpCacheability.No Cache)

  '## Retrieve systemdata
  Dim SQL = "SELECT Systemtitle, Nformat1, Nformat2 FROM System"
  Dim Sqlcommand As New OdbcCommand(SQL, Dbconnect.Connection)
  Dim Sqlreader As OdbcDataReader = Sqlcommand.ExecuteReader()
  Systemtitle = Sqlreader.Item(0) 'Public propery
  Nformat1 = Sqlreader.Item(1) 'Public propery
  Nformat2 = Sqlreader.Item(2) 'Public propery

  '## Set userinfo
  If (Not ((Systempage = "1") Or (Systempage = "0"))) Then
  End If
End Sub

Based on this, is this the correct way to do what I want, or am I doing it completely wrong here?

About the third answer, so it's not possible to retrieve the value from one user control to another user control without involving the page?

Thanks, Martin