RE: Reference A var on Master Page from User Control

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Phillip,
Thanks so much for the reply. I've started to look into this and have come
across one issue. It seems that AddHandler is not supported in ASP.NET. Is
this true, if so, what includes do I need to include into the project. Here
is what I have so far.
Just a refresher of what I needed:
1. User enter UserId & password and selects submit.
2. The login User control will check what roles they have and create a User
Object.
3. Set the User Object to a Value stored in the MasterPage.
4. Purchasing screen shown and depending on the Role the user has will
determine what the user sees (Admin/Standard user).
So what I have come up with so far based on the event based noticifaction.
Stand alone Class File:
Public Class UserInfoEventArgs
Inherits EventArgs
Private _User as User

Public sub new(UserInfo as User )
_User = UserInfo
End Sub

Public ReadOnly Property UserInfo() as User
Get
UserInfo = _User
End Get
End Property
End Class

In the Login User Control:
Public Event Alarm as UserInfoEventHandler

Protected OverRidable Sub OnAlarm(e as UserInfoEventArgs )
RaiseEvent Alarm(me, e)
End Sub

Sub AuthenticateUser(userId as string, password as password)
'Do stuff here.......
'Now feed the UserInfo to the MasterPage via a Event
Dim e as New UserInfoEventArgs(lUser)
OnAlarm(e)
'Do more stuff....
end sub

In the MasterPage:
AddHandler Alarm, AddressOf OnCurrentUser

Public sub OnCurrentUser(sender as Object, e as UserInfoEventArgs )
_CurrentUser = e.UserInfo
End Sub
Note: I get a syntax error on the AddHandler line.

Do I have this setup correctly for an ASP.NET page? Thanks again for any
suggestions.
Michael




"Phillip Williams" wrote:

Michael,

If I understood your scenario correctly, then you have a master page (which
is a control on the page) that has a child user control that needs to
communicate data (users information that is generated perhaps after some user
input) to the parent control (the master page).

In such scenarios (of communicating data between 2 controls on a web form)
you need to look at using events. When the child user control finishes
collecting the user info, then you raise an event, that would be consumed by
the parent control (the master page), which in turn would display the data on
its control (or do whatever other processing required).

To understand how to raise an event from the child control and how to
consume it by the master page, review these articles on the MSDN:
http://msdn2.microsoft.com/en-us/library/17sde2xt.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Michael" wrote:

I have setup a public variable in the Master Page "code-behind-file". Now I
would like to set that value from the UserControl, but I can't seem to find a
way to do this. Does anyone have any ideas? I'm basically trying to set it up
so that I can keep the User infor (userid, ect) in the Masterpage so that
other pages can access it. Thanks for any ideas.
Michael

.



Relevant Pages

  • Re: MasterPage Problems
    ... Template are extracted and integrated into the control tree as required. ... MasterPage.FindControl("myLabel") is your object from masterPage, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: 2 Questions about using AJAX with Master Page
    ... You say that all so well but tell me then please; does MasterPage ... is but the compiler "redims" the control tree so it can wrap the MasterPage around it? ... A MasterPage is a template and merging container UserControl which can host other controls. ... It inherits directly from UserControl, which in turn inherits from TemplateControl. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: 2 Questions about using AJAX with Master Page
    ... You say that all so well but tell me then please; does MasterPage ... if strictly from User Control as you imply why then is the MasterPage not injected --into-- the control tree the way a User Control is but the compiler "redims" the control tree so it can wrap the MasterPage around it? ... The MasterPage class derives (inherits, actually) from Control, ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Reference A var on Master Page from User Control
    ... AddHandler NameOfObject.Event, AddressOf MethodHandlingTheEvent ... e as UserInfoEventArgs) Handles ... The login User control will check what roles they have and create a User ... Set the User Object to a Value stored in the MasterPage. ...
    (microsoft.public.dotnet.framework.aspnet)