mlee1steph
Programmer
Hi Everyone,
I'm working on my first ASP.NET app and have been trying to access a var located in the MasterPage. I've tried using a Property to access the var but could not get that to work, so it was suggested that I try events. So here is the standard flow I'll need:
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. I read somewhere that ASP.NET handles events differently than Windows apps. So if AddHandler is not correct, then what should I be using.
Do I have this setup correctly for an ASP.NET page? Thanks for any suggestions.
Michael
I'm working on my first ASP.NET app and have been trying to access a var located in the MasterPage. I've tried using a Property to access the var but could not get that to work, so it was suggested that I try events. So here is the standard flow I'll need:
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. I read somewhere that ASP.NET handles events differently than Windows apps. So if AddHandler is not correct, then what should I be using.
Do I have this setup correctly for an ASP.NET page? Thanks for any suggestions.
Michael