DropDownList, CreateUserWizard - postback issues

R

RosH

Hi Everyone,

I have a CreateUserWizard my public sign up page of my website. I
have edited the wizard to include collection of other personal
information. I have a DropDownList for the selection of the
Graduation year. Find the code below to Insert all the additional
information to another database when a new ASP user is created. The
DropDownList gets cleared of all data during execution of this code.
Your thoughts on the solution expected.

DropDownList Properties:

* EnableViewState: True
* AppendDataBoundItems: False
* AutoPostBack: False
* Causes Validation: False



Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Page.IsPostBack = False Then

Dim YearList As DropDownList =
CreateUserWizardStep1.ContentTemplateContainer.FindControl("Year")
Dim nStartYear As Integer = 1980
Dim nCurrentYear As Integer = CType(Date.Now.Year,
Integer)

For index As Integer = nStartYear To nCurrentYear
YearList.Items.Add(index)
Next

End If
End Sub


Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object,
ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser

Dim UserNameEntered As TextBox =
CreateUserWizardStep1.ContentTemplateContainer.FindControl("Username")
Dim DateOfBirth As TextBox =
CreateUserWizardStep1.ContentTemplateContainer.FindControl("DateOfBirth")
Dim YearList As DropDownList =
CreateUserWizardStep1.ContentTemplateContainer.FindControl("Year")

Dim User1 As MembershipUser =
Membership.GetUser(UserNameEntered.Text)
Dim UserGUID As Object = User1.ProviderUserKey
Dim DOB As Date = Date.ParseExact(DateOfBirth.Text, "dd/MM/
yyyy", Nothing)

'The Problem is seen in the line below, the DropDownList (YearList)
gets cleared of all
'Items which makes me unable to find the Selected Value of the Year
of Graduation

Dim GraduatedYear As Date =
Date.ParseExact(YearList.SelectedValue, "yyyy", Nothing)

Dim DataSource As SqlDataSource =
CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertUserInfo")


DataSource.InsertParameters.Add("ASPUserId",
UserGUID.ToString())
DataSource.InsertParameters.Add("GraduationYear",
GraduationYear)
DataSource.Insert()

Roles.AddUserToRole(UserNameEntered.Text, "MemberUser")

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top