Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

createUserWizard and profile values 1

Status
Not open for further replies.

jordanking

Programmer
Sep 8, 2005
351
0
0
hello,

I have a create user wizard that also assigns some custom role and profile values in the createdUser event of the control. Once this operation is complete and the user clicks the continue button the user is redirected to a role restricted "Members" page/directory.

The problem is that the "Members" page the user is directed to has a label that displays some personal info from the profile and it throws an error:
Object reference not set to an instance of an object.
which happens on line 45 wich uses a loginView control
Code:
Line 39:        If System.Web.HttpContext.Current.User.Identity.IsAuthenticated = False Then
Line 40:            Dim loginButton As Button = DirectCast(Me.LoginView1.FindControl("logEFFU").FindControl("LoginButton"), Button)
Line 41:            Me.Panel1.DefaultButton = loginButton.UniqueID
Line 42:        Else
Line 43:             Dim logName As New Label
Line 44:             logName = CType(LoginView1.FindControl("logName"), Label)
Line 45:             logName.Text = Profile.FirstName + " " + Profile.LastName
Line 46:             logName.CssClass = "ItaliBold"
Line 47:         End If
but this error does not appear if the user logs in through the login control after the user is created. It only appears the first time the user is redirected to this "Members" page after using the createUser Control.

does anyone know why this happens only after using the createUser control?

.....
I'd rather be surfing
 
I assum the profile object is not instantiated. You will have to trace through the code. You did not post enought for us to see the whole process. Use the debugger first for each scenario.
 
thanks for the reply

when i use the debugger and the error i mentioned is caught, i use the immediate window to test the profile values and they exist. the following code is where the profile values are set:
Code:
    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser

        '' explicitly create profile object
        Dim effuProfile As ProfileCommon = ProfileCommon.Create(CreateUserWizard1.UserName, True)

        ''set the first and last and IAFF name from the session variables
        effuProfile.FirstName = SessionHandler.FirstName
        effuProfile.LastName = SessionHandler.LastName
        effuProfile.intIAFF = SessionHandler.IAFF

        ''capture values fromthe optional information text boxes
        Dim txtAddress As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress"), TextBox)
        Dim txtCity As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCity"), TextBox)
        Dim txtPostal As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPostal"), TextBox)
        Dim txtProvince As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtProvince"), TextBox)
        Dim txtPhone As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPhone"), TextBox)

        If txtAddress.Text <> String.Empty Then
            effuProfile.Address = txtAddress.Text
        End If
        If txtCity.Text <> String.Empty Then
            effuProfile.City = txtCity.Text
        End If
        If txtProvince.Text <> String.Empty Then
            effuProfile.Province = txtProvince.Text
        End If
        If txtPostal.Text <> String.Empty Then
            effuProfile.Postal = txtPostal.Text
        End If
        If txtPhone.Text <> String.Empty Then
            effuProfile.Phone = txtPhone.Text
        End If

        ''save profile
        effuProfile.Save()

        ''add user to default role
        Roles.AddUserToRole(CreateUserWizard1.UserName, "EFFU_Mem")

    End Sub

.....
I'd rather be surfing
 
You will have to debug and find what ojbect it is looking for that is not instantiated. That is what the error is telling you. Then from there figure out what code needs to be fixed.
 
sorry, i don't totally understand. I did run the page in debug and it told me what line the error was generated on and it was a label inside of a loginView control. Does that mean the label is not instantiated? This code works when the user logs in through the login control, just not when redirected from the createUserWizard.

is there a way to test to see if the profile or label is instatiated properly?

.....
I'd rather be surfing
 
simply looking over the code samples provided. You do a lot of graph traversing and casting. This is a read flag to me, as this is not the purpose of the CreateUserWizard. either use the CreateUserWizard as it was intended, or build your own.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
jmeckley

i am not sure what you mean by graph traversing. the create user wizard works, all the values and roles are created properly, the problem is a label in a loginview on a masterpage that displays the profile values gets an error but only when redirected from the create user wizard. otherwise, the code works for all other users that have already been created.

.....
I'd rather be surfing
 
this is an example of traversing the object graph:
CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress")

the page should not care about the ContentTemplateContainer or what controls is may contain. the purpose of the ContentTemplateContainer is to encapsulate the details of how a user is created. If this is what you want just drop the labels/input fields directly on the form.

now this may be working in your current scenario, but it's a bad practice. This is a classic example of Law of Determer. Phil Haack has been posting about this concept recently. More about when it's OK to ignore the rule. but knowing how the concept works will help you know when it's Ok to ignore it.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
so, just for clarity. don't use the createUserWizard if i need customization, or should i reference the controls within it differently.

.....
I'd rather be surfing
 
don't use the createUserWizard if i need customization,
correct.

It has been my experience that Webforms and web server controls work exactly one way. Any deviation creates more problems than results. Honestly, html is not difficult at all. i would recommend abandoning webforms all together in favor of an MVC framework like Monorail or MS MVC. not only are they extensible on the server side, but you can choose a view engine you want: webforms (but not the postback webforms), spark, nvelocity, brail, aspview, etc.

i digress though. If the Law of Detemeter intrigued you check out SOLID design principles and GOF (gang of four) patterns. This will lead you down the OOP rabbit hole:)

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
thanks for the info, a lot of it is beyond me and i plan to look into it.

.....
I'd rather be surfing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top