If in form1 I use User user = new User(); to create my user object. When I go to form2 how do I reference the same user object
Thanks Mike
If in form1 I use User user = new User(); to create my user object. When I go to form2 how do I reference the same user object
Thanks Mike
object reference
AllDisplayNamesRBelongToUs
ThisUser.login and User.login are two seperate instances....
I take it form1 is your startup object...and you are actually trying to get a single instance of a user...that being the case use the singleton class for your user...
Public Class MySingletonClass
Private Shared m_User as User
Public Shared Function MyUser()as User
If IsNothing(m_User) then
m_User = New User
Return m_User
else
return m_User
end If
end Function
end Class
Form Code:
Public Class Form1
Dim MyUser as User = MySingletonCLass.MyUser
end Class
Public Class Form2
Dim MyUser as User = MySingletonClass.MyUser
end Class
ChandraP
Cheers and happy Monday!
Mike
Kuik
Singleton Class
Public Class MySingletonClass
Private m_Form1 as Form1
Public Function MyForm1()as Form1
If IsNothing(m_Form1) then
m_Form1 = new Form1
Return m_Form1
else
return m_Form1
end If
end Function
end Class
Form1 Code:
Public Class Form1
m_User as New User
Public Property MyUser() as User
Get
Return m_User
End Get
Set(ByVal value As User)
m_User = value
End Set
End Property
end Class
Form2 Code
Public Class Form2
Private Sub Test
Dim ThisUser as User =MySingletonClass.MyForm1.MyUser
....Do Something
end Sub
end Class
Ross Miltenberg
rgny
How would I do number 1
on Form 1
public
User user { get{
return user;}
set{
User user =
new User();}
}
Then on Form2 how do I get a reference to form1
Thanks
Mike
Dub
Private
Shared m_Form1 As Form1 Public Shared Function MyForm1()ripleym
I have a similar problem but with using a customRoleProvider
My IsUserInRole method is set to public overrides isUserInrole
so when i change
Public Overridable function IsUserIRole(username as string, Rolename as string)
to
Shared Overridable function ...
VS yells at me and says that I can;t share an overridable function any ideas
where i'm actiually getting the error is here
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsUserInRole(User.Identity, "Administrator") Then End If End Suband this is my method in my CustomRoleProvider.vb class
' ' RoleProvider.IsUserInRole ' Public Overrides Function IsUserInRole(ByVal username As String, ByVal roleName As String) As Boolean Dim UserIsInRole As Boolean = False Dim conn As SqlConnection = New SqlConnection(connectionString) Dim cmd As SqlCommand = New SqlCommand("select count(8) from UsersInRoles " & _ " where Username = and Rolename = and ApplicationName = ", conn) cmd.Parameters.Add("@username", SqlDbType.VarChar, 255).Value = username cmd.Parameters.Add("@Rolename", SqlDbType.VarChar, 255).Value = roleName cmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = ApplicationName Try conn.Open() Dim numRecs As Integer = CType(cmd.ExecuteScalar(), Integer) If numRecs > 0 Then UserIsInRole = True End If Catch e As SqlException If WriteExceptionsToEventLog Then WriteToEventLog(e, "IsUserInRole") Else Throw e End If Finally conn.Close() End Try Return UserIsInRole End Function and at the tope of my default.aspx.vb page im using Import CustomRoleProvider any help would be greatly appreciated.. Thanks DeanoPatrickC
Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickMessageBox.Show(ThisUser.login)
End SubI know the property is set because I can see it on Form1 with
MessageBox.Show(User.login)
am I still missing something here It is not using the same user object that was created in form1
Thanks again
Mike
Swatanya
on this line
ThisUser As User = MySingletonClass.MyForm1.MyUserDim
I imported everything
Imports
singleton_class_test_vb.MySingletonClassImports
singleton_class_test_vb.UserImports
singleton_class_test_vb.Form1Imports
singleton_class_test_vb.Form2and that didn't help.
Thanks for spoon feeding me this. I am trying to write good OOP code and I think this will get me past a big hurdle.
Thanks again for you valuable time.
Mike