CreateUserWizard secondary table Return_Value
Hi
Using SQLDataSource and SQL 2005 Stored Procedure I've been successful in creating multiple additional CreateUser fields saving them to "tbl_UserDetails" table.
I pass the UserId to the tbl_UserDetails as well. What I'm struggling with is retreiving the new tbl_UserDetails "Details_Id" (RETURN_VALUE) t-sql RETURN SCOPE_IDENTITY().
I want to integrate it into the Profile data (see SQLDSInsert_Inserting).
I'm not sure if the problem retreiving the RETURN_VALUE is in the SQLDSInsert_Inserting code used or if I'm not addressing the retreival in the "correct" stage of "the Insert process". See below.
Thanks
Imports Telerik.WebControls
Imports SITE.DAL.DBAccess
Imports System.Data
Imports System.Data.SqlClient
Partial Class Site_Pages_Registration
Inherits System.Web.UI.Page
Protected WithEvents Update_Date As WebControls.HiddenField
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("Record") IsNot Nothing Then
CreateUserWizard1.MoveTo(CompleteWizardStep1)
End If
End Sub
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
If user Is Nothing Then
Throw New ApplicationException("Can't find the user.")
End If
Dim DetailsInsert As SqlDataSource = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("SQLDSInsert"), SqlDataSource)
Dim UserId As Guid = DirectCast(user.ProviderUserKey, Guid)
Session("NewUserId") = UserId
Dim Details_FirstName As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_FirstName"), TextBox)
Dim Details_LastName As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_LastName"), TextBox)
Dim Details_MI As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_MI"), TextBox)
Dim Details_Title As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Title"), TextBox)
Dim Details_Company As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Company"), TextBox)
Dim Details_1Comm As Telerik.WebControls.RadMaskedTextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox)
Dim Details_1CommType As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox)
Dim Details_2Comm As Telerik.WebControls.RadMaskedTextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox)
Dim Details_2CommType As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox)
Dim Details_Address As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Address"), TextBox)
Dim Details_City As TextBox = CType(CreateUserWizardStep0.ContentTemplateContain er.FindControl("Details_City"), TextBox)
Dim Details_State As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox)
Dim Details_Zip As Telerik.WebControls.RadMaskedTextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox)
Dim Details_UserTypeId As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_UserTypeId"), Telerik.WebControls.RadComboBox)
Dim Details_ReceiveEmail As CheckBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_ReceiveEmail"), CheckBox)
DetailsInsert.Insert()
Dim UserType As Telerik.WebControls.RadComboBox = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_UserTypeId"), Telerik.WebControls.RadComboBox)
Session("UserType") = UserType.SelectedValue.ToString
End Sub
Protected Sub SQLDSInsert_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs)
Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
e.Command.Parameters("@UserId").Value = user.ProviderUserKey
e.Command.Parameters("@Details_FirstName").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_FirstName"), TextBox).Text
e.Command.Parameters("@Details_LastName").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_LastName"), TextBox).Text
e.Command.Parameters("@Details_MI").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_MI"), TextBox).Text
e.Command.Parameters("@Details_Company").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Company"), TextBox).Text
e.Command.Parameters("@Details_Title").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Title"), TextBox).Text
e.Command.Parameters("@Details_1Comm").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox).Text
e.Command.Parameters("@Details_1CommType").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox).SelectedValue
e.Command.Parameters("@Details_2Comm").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox).Text
e.Command.Parameters("@Details_2CommType").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox).SelectedValue
e.Command.Parameters("@Details_Address").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Address"), TextBox).Text
e.Command.Parameters("@Details_City").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_City"), TextBox).Text
e.Command.Parameters("@Details_State").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox).SelectedValue
e.Command.Parameters("@Details_Zip").Value = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox).Text
e.Command.Parameters("@Details_UserTypeId").Value = Int32.Parse(CType(CreateUserWizard1.CreateUserStep .ContentTemplateContainer.FindControl("Details_Use rTypeId"), Telerik.WebControls.RadComboBox).SelectedValue)
e.Command.Parameters("@Details_ReceiveEmail").Valu e = CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_ReceiveEmail"), CheckBox).Checked
e.Command.Parameters("@RETURN_VALUE").Direction = ParameterDirection.ReturnValue
Dim Record As Integer = e.Command.Parameters("@RETURN_VALUE").Value
'Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
Dim pb As ProfileBase = ProfileBase.Create(user.UserName)
pb.SetPropertyValue("FirstName", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_FirstName"), TextBox).Text)
pb.SetPropertyValue("LastName", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_LastName"), TextBox).Text)
pb.SetPropertyValue("UserName", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("UserName"), TextBox).Text)
pb.SetPropertyValue("Record", Record.ToString)
pb.SetPropertyValue("Company", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Company"), TextBox).Text)
pb.SetPropertyValue("Title", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Title"), TextBox).Text)
pb.SetPropertyValue("Comm1", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_1Comm"), Telerik.WebControls.RadMaskedTextBox).Text)
pb.SetPropertyValue("Comm1Type", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_1CommType"), Telerik.WebControls.RadComboBox).SelectedValue)
pb.SetPropertyValue("Comm2", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_2Comm"), Telerik.WebControls.RadMaskedTextBox).Text)
pb.SetPropertyValue("Comm2Type", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_2CommType"), Telerik.WebControls.RadComboBox).SelectedValue)
pb.SetPropertyValue("Address", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Address"), TextBox).Text)
pb.SetPropertyValue("City", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_City"), TextBox).Text)
pb.SetPropertyValue("State", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_State"), Telerik.WebControls.RadComboBox).SelectedValue)
pb.SetPropertyValue("Zip", CType(CreateUserWizard1.CreateUserStep.ContentTemp lateContainer.FindControl("Details_Zip"), Telerik.WebControls.RadMaskedTextBox).Text)
pb.Save()
End Sub
Protected Sub CompleteButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lblRegisterCompleteName As Label = CreateUserWizard1.CompleteStep.FindControl("lblReg isterCompleteName"), Label
lblRegisterCompleteName.Text = Profile.FirstName & " " & Profile.LastName
Dim Muser As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
If Muser Is Nothing Then
Throw New ApplicationException("Can't find the user.")
End If
Muser.IsApproved = False
End Sub
Protected Sub btnTeamProfile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Dim conn As SqlConnection = New SqlConnection(connString)
'conn.Open()
'Dim command As SqlCommand = New SqlCommand("UserDetails_Insert", conn)
'command.CommandType = Data.CommandType.StoredProcedure
'Dim dID As System.Data.SqlClient.SqlParameter = command.Parameters.Add("@Details_Id", System.Data.SqlDbType.Int)
'dID.Direction = System.Data.ParameterDirection.ReturnValue
'command.ExecuteScalar()
'conn.Close()
'Dim RecordId As String = command.Parameters("@Details_Id").Value.ToString()
Response.Redirect("Profile.aspx")
End Sub
Protected Sub CompleteWizardStep1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles CompleteWizardStep1.PreRender
Dim btnAppraiserProfile As Button = CType(CompleteWizardStep1.ContentTemplateContainer .FindControl("btnAppraiserProfile"), Button)
If Session("UserType") = "2" Then
btnAppraiserProfile.Visible = True
Else
btnAppraiserProfile.Visible = False
End If
End Sub
Protected Sub SQLDSInsert_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs)
Response.Redirect("Registration.aspx")
End Sub
End Class
|