I have searched all over the internets for a solution to this problem and there are many ways to work around it but I'm wondering if there is a more simple solution.
I have asp.net 2.0 working with SQL Server 2005 Express and IIS 5.0. I made a page that contains the CreateUserWizard so people can get access to rest of my applications. Using the default (asp:CreateUserWizard) allows us to store data such as username, email address, and password in the aspnetdb database using this provider.
[HTML]<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>[/HTML]
Now I want to store some more data related to the user so I open up the SQL Server Management Studio. I navigate to +MyServer +Databases +aspnetdb +Tables and modify the dbo.aspnet_Users table ADDING 2 columns named;
FirstName nvarchar(50) null
and
LastName nvarchar(50) null
Now I create the text boxes for these new fields in my createuser.aspx page with the following code;
[HTML]<asp:CreateUserWizardStep runat="server">
<ContentTemplate>
<table border="0">
<tr>
<td align="center" colspan="2">
Please fill in all the fields.</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="FirstNameLabel" runat="server" AssociatedControlID="FirstName">First Name</asp:Label>
</td>
<td>
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="FirstNameRequired" runat="server" ControlToValidate="FirstName" ErrorMessage="First Name Is Required." ToolTip="First name is required" ValidationGroup="CreateUserWizard1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="LastNameLabel" runat="server" AssociatedControlID="LastName">Last Name</asp:Label>
</td>
<td>
<asp:TextBox ID="LastName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="LastName" ErrorMessage="Last Name Is Required." ToolTip="Last name is required" ValidationGroup="CreateUserWizard1"></asp:RequiredFieldValidator>
</td>
</tr>
and so on with the rest of the default controls...
[/HTML]
Now, how do I get ASP to recognize that it should be storing FirstName and LastName into the aspnetdb_users table? I've tried just running the page the way it is now and I get no errors but the data entered into the new TextBox controls does not get saved into the aspnetdb_users table. After looking though out the internet I have found many different ways of doing this but the best one I like the most is done by catching the OnCreatedUser event from the CreateUserWizard and it takes the text entered in the new controls and saves it somehow. This is what stumps me here because all of the tutorials I've seen leaves this procedure empty.
So I add this to the asp:createuserwizard
[HTML]<asp:CreateUserWizard ID="CreateUserWizard1" OnCreatedUser="CreateUserWizard1_CreatedUser()" runat="server">[/HTML]
and in the <script runat="server"> I add something like this???
[HTML]<script runat="server">
Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal E As EventArgs) Handles CreateUserWizard1.CreatedUser
Dim FName As TextBox
Dim LName As TextBox
Dim UserID As TextBox
FName = CType(FindControl("FirstName"), TextBox)
LName = CType(FindControl("LastName"), TextBox)
UserID = CType(FindControl("UserName"), TextBox) 'This lets me match to the newly created record in the table...
??? save FName.innertext TO aspnetdb_users.FirstName WHERE UserID.innertext = aspnetdb_users.UserName
save LName.innertext TO aspnetdb_users.LastName WHERE UserID.innertext = aspnetdb_users.UserName
This is where I have a problem. I really need to figure this out also because I plan on creating an order entry database with asp for the front end in the near future.
End Sub
</script>[/HTML]
Thanks,
James