locked
Customized Create User Wizard VB Code RRS feed

  • Question

  • User-1694337237 posted
    I am having some trouble converting some C code to VB. I am not experienced at all in C and I have little experience with VB. If anyone can help me I would very much appreciate it!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    C CODE:

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

    {

    TextBox UserNameTextBox =

    (TextBox)CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName");

    SqlDataSource DataSource =

    (SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");

    MembershipUser User = Membership.GetUser(UserNameTextBox.Text);

    object UserGUID = User.ProviderUserKey;

    DataSource.InsertParameters.Add("UserId", UserGUID.ToString());

    DataSource.Insert();

    }

    <o:p> </o:p>

    VB CODE AFTER USING A CONVERTER:

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)

    Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)

    Dim DataSource As SqlDataSource = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource) <o:p></o:p>

    Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)

    Dim UserGUID As Object = User.ProviderUserKey

    DataSource.InsertParameters.Add("UserId", UserGUID.ToString())

    DataSource.Insert()

    End Sub<o:p></o:p><o:p> </o:p>

    I am receiving errors in the highlighted areas; “CreateUserWizardStep1” is not declared. If I change it to what it does suggest, although I do not want to change it, I get errors with the “ContentTemplateContainer” portion.

    Wednesday, November 19, 2008 3:02 PM

Answers

  • User1006193418 posted

     

    From my original conversion, I changed the ID to be 1 instead of 2. So my current tag is ID="CreatUserWizardStep1". Thanks for the thought, do you have anyother idea's of why it is saying that "CreatUserWizardStep1" is not declared? Thanks again! 

    Hi Thomas,

    Yes, CreateUserWizardStep1 cannot be found by the compiler in this case for the reason it is in the Template. 

    So, you may need to use Control.FindControl method to get your CreateUserWizardStep1 first. You can refer to MSDN for more information about Control.FindControl method.

    Here are the modified codes which may work for you. Have a try on it and let me if there is still any problem.

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
        'use Control.FindControl method to find the CreateUserWizardStep1 step by step
        Dim CreateUserWizard1 As CreateUserWizard
        CreateUserWizard1 = CType(LoginView1.FindControl("CreateUserWizard1"), CreateUserWizard)
        Dim CreateUserWizardStep1 As CreateUserWizardStep
        CreateUserWizardStep1 = CType(myCreateUserWizard.FindControl("CreateUserWizardStep1"), CreateUserWizardStep)
    
        'then, you can use it wherever you need
        Dim UserNameTextBox As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
        Dim DataSource As SqlDataSource = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim UserGUID As Object = User.ProviderUserKey
        DataSource.InsertParameters.Add("UserId", UserGUID.ToString())
        DataSource.Insert()
    
    End Sub
    

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 21, 2008 2:36 AM

All replies

  • User397347636 posted

    Which converter are you using?  Why would it change CreateUserWizardStep2 to CreateUserWizardStep1 ??  Obviously you have to correct that first.

    What error do you get when you correct the converter output to use the correct variable name?

    Wednesday, November 19, 2008 3:27 PM
  • User-1694337237 posted

    Which converter are you using?  Why would it change CreateUserWizardStep2 to CreateUserWizardStep1 ??  Obviously you have to correct that first.

    What error do you get when you correct the converter output to use the correct variable name?

     
    I am sorry, I did not mention that in my application I need it to be CreateUserWizardStep1. I used the converter here.
     
    I originally got this code as an example and it was written in C. So I made one change after converting it and it did not work for me.
     
    Thanks for your response and time!
    Wednesday, November 19, 2008 3:38 PM
  • User397347636 posted

    Then the conversion looks fine to me.

    What error are you getting?

    Wednesday, November 19, 2008 3:50 PM
  • User-1694337237 posted

    Then the conversion looks fine to me.

    What error are you getting?

     
    The error message says that "CreateUserWizardStep1" is not declared. Do I need to declare this in the VB code? I have it declared as a ID tag within my .net document. Usually this is all I have to do...
    Wednesday, November 19, 2008 4:19 PM
  • User-990694832 posted

     

    CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)

    is off a little

    try

    CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox)

    try a 2 instead of a 1

    a second pair of eyes always helps....

    Hope this helps

    DK

     

    Thursday, November 20, 2008 8:46 AM
  • User-1694337237 posted

     

    CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)

    is off a little

    try

    CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox)

    try a 2 instead of a 1

    a second pair of eyes always helps....

    Hope this helps

    DK

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

     <o:p></o:p>From my original conversion, I changed the ID to be 1 instead of 2. So my current tag is ID="CreatUserWizardStep1". Thanks for the thought, do you have anyother idea's of why it is saying that "CreatUserWizardStep1" is not declared? Thanks again!<o:p></o:p> <o:p></o:p>VB CODE:<o:p></o:p>

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)

    Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)

    Dim DataSource As SqlDataSource = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)

    Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)

    Dim UserGUID As Object = User.ProviderUserKey

    DataSource.InsertParameters.Add("UserId", UserGUID.ToString())

    DataSource.Insert()

    End Sub

     

    <o:p></o:p> PAGE CODE:

    <asp:LoginView ID="LoginView1" runat="server">

    <AnonymousTemplate>

    <table width="560" align="center">

    <tr>

    <td width="100%">

    <img src="images/welcome.gif" /></td>

    </tr>

    <tr>

    <td width="100%">&nbsp;</td>

    </tr>

    <tr>

    <td width="100%" class="h1">Login</td>

    </tr>

    <tr>

    <td width="100%"><img src="images/line.gif" /></td>

    </tr>

    <tr>

    <td width="100%">

    <asp:Login ID="Login1" runat="server" TitleText="" PasswordRecoveryText="Forgot your password?"

    PasswordRecoveryUrl="recoverpassword.aspx" DisplayRememberMe="False">

    <FailureTextStyle CssClass="incorrect" />

    <CheckBoxStyle CssClass="login" />

    <ValidatorTextStyle CssClass="incorrect" />

    <LabelStyle CssClass="login" />

    </asp:Login>

    </td>

    </tr>

    <tr>

    <td width="100%" class="h1">

    New User? Please Register</td>

    </tr>

    <tr>

    <td width="100%">

    <img src="images/line.gif" /></td>

    </tr>

    <tr>

    <td width="100%">

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">

    <WizardSteps>

    <asp:WizardStep ID="CreateUserWizardStep0" runat="server">

    <table>

    <tr>

    <td align="right" class="login">

    <asp:Label ID="Label1" runat="server" AssociatedControlID="Hospital">Hospital

    Affiliation:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="Hospital" runat="server"></asp:TextBox>

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

    ControlToValidate="Hospital" CssClass="incorrect"

    ErrorMessage="Hospital Affiliation is required." ToolTip="Hospital Affiliation is required."

    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

    </table>

    </asp:WizardStep>

    <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">

    <ContentTemplate>

    <table border="0">

    <tr>

    <td align="right" class="login">

    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User

    Name:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>

    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"

    ControlToValidate="UserName" CssClass="incorrect"

    ErrorMessage="User Name is required." ToolTip="User Name is required."

    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

     

    <tr>

    <td align="right" class="login">

    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>

    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"

    ControlToValidate="Password" CssClass="incorrect"

    ErrorMessage="Password is required." ToolTip="Password is required."

    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

    <tr>

    <td align="right" class="login">

    <asp:Label ID="ConfirmPasswordLabel" runat="server"

    AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>

    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"

    ControlToValidate="ConfirmPassword" CssClass="incorrect"

    ErrorMessage="Confirm Password is required."

    ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

    <tr>

    <td align="right" class="login">

    <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="Email" runat="server"></asp:TextBox>

    <asp:RequiredFieldValidator ID="EmailRequired" runat="server"

    ControlToValidate="Email" CssClass="incorrect"

    ErrorMessage="E-mail is required." ToolTip="E-mail is required."

    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

    <tr>

    <td align="right" class="login">

    <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security

    Question:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="Question" runat="server"></asp:TextBox>

    <asp:RequiredFieldValidator ID="QuestionRequired" runat="server"

    ControlToValidate="Question" CssClass="incorrect"

    ErrorMessage="Security question is required."

    ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

    <tr>

    <td align="right" class="login">

    <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security

    Answer:</asp:Label>

    </td>

    <td>

    <asp:TextBox ID="Answer" runat="server"></asp:TextBox>

    <asp:RequiredFieldValidator ID="AnswerRequired" runat="server"

    ControlToValidate="Answer" CssClass="incorrect"

    ErrorMessage="Security answer is required."

    ToolTip="Security answer is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

    </td>

    </tr>

    <tr>

    <td align="center" colspan="2">

    <asp:CompareValidator ID="PasswordCompare" runat="server"

    ControlToCompare="Password" ControlToValidate="ConfirmPassword"

    CssClass="incorrect" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."

    ValidationGroup="CreateUserWizard1"></asp:CompareValidator>

    </td>

    </tr>

    <tr>

    <td align="center" class="incorrect" colspan="2" style="color:Red;">

    <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>

    </td>

    </tr>

    </table>

     

    <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:PerinatalConnectionString %>"

    InsertCommand="INSERT INTO [UserHospitalList] ([UserId], [HospitalAffiliation]) VALUES (@UserId, @Hospital)"

    ProviderName="<%$ ConnectionStrings:PerinatalConnectionString.ProviderName %>">

    <InsertParameters>

    <asp:ControlParameter Name="Hospital" Type="String" ControlID="Hospital" PropertyName="Text" />

    </InsertParameters>

     

    </asp:SqlDataSource>

     

    </ContentTemplate>

    </asp:CreateUserWizardStep>

    <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

    </asp:CompleteWizardStep>

    </WizardSteps>

    <ValidatorTextStyle CssClass="incorrect" />

    <LabelStyle CssClass="login" />

    <ErrorMessageStyle CssClass="incorrect" />

    </asp:CreateUserWizard>

    </td>

    </tr>

    </table>

    </AnonymousTemplate>

    <LoggedInTemplate>

    <table width="560" align="center">

    <tr>

    <td width="100%">

    <img src="images/mainmenu.gif" /></td>

    </tr>

    <tr>

    <td width="100%">&nbsp;</td>

    </tr>

    <tr>

    <td class="h1">Available Tests</td> </tr>

    <tr>

    <td width="100%"><img src="images/line.gif" /></td>

    </tr>

    <tr>

    <td width="100%">

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2">

    <ItemTemplate>

    <asp:HyperLink

    ID="HyperLink1" runat="server" NavigateUrl='<%# "start.aspx?testid=" & Eval("QuizID") %>'

    Text='<%# Eval("Title") %>'></asp:HyperLink><br />

    &nbsp;<asp:Label

    ID="DescriptionLabel" runat="server" CssClass="generaltext" Text='<%# Eval("Description") %>'></asp:Label>&nbsp;<br />

    <br />

    </ItemTemplate>

    </asp:DataList>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

    SelectCommand="SELECT [Title], [Description], [QuizID] FROM [Quiz]"></asp:SqlDataSource>

    </td>

    </tr>

    <tr>

    <td width="100%">&nbsp;</td>

    </tr>

    <tr>

    <td width="100%" class="h1">Test Result History</td>

    </tr>

    <tr>

    <td width="100%">

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"

    DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="555px">

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" />

    <Columns>

    <asp:BoundField DataField="Title" HeaderText="Quiz" SortExpression="Title" >

    <HeaderStyle HorizontalAlign="Left" />

    <ItemStyle HorizontalAlign="Left" />

    </asp:BoundField>

    <asp:BoundField DataField="DateTimeComplete" DataFormatString="{0:d}" HeaderText="Completed"

    SortExpression="DateTimeComplete" >

    <FooterStyle Width="150px" />

    <HeaderStyle Width="150px" />

    <ItemStyle HorizontalAlign="Center" Width="150px" />

    </asp:BoundField>

    <asp:BoundField DataField="Score" HeaderText="Score" SortExpression="Score" >

    <FooterStyle Width="50px" />

    <HeaderStyle Width="50px" />

    <ItemStyle HorizontalAlign="Center" Width="50px" />

    </asp:BoundField>

    </Columns>

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    <HeaderStyle Font-Bold="True" CssClass="complete" />

    <EditRowStyle BackColor="#999999" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

    SelectCommand="SELECT Quiz.Title, UserQuiz.DateTimeComplete, UserQuiz.Score FROM UserQuiz INNER JOIN Quiz ON UserQuiz.QuizID = Quiz.QuizID WHERE (UserQuiz.UserName = @UserName) ORDER BY UserQuiz.DateTimeComplete">

    <SelectParameters>

    <asp:SessionParameter Name="UserName" SessionField="UserName" />

    </SelectParameters>

    </asp:SqlDataSource>

    </td>

    </tr>

    <tr>

    <td width="100%">&nbsp;</td>

    </tr>

    <tr>

    <td width="100%" class="h1">Change Password</td>

    </tr>

    <tr>

    <td width="100%"><img src="images/line.gif" /></td>

    </tr>

    <tr>

    <td width="100%">

    <asp:ChangePassword ID="ChangePassword1" runat="server" ChangePasswordTitleText="">

    <LabelStyle CssClass="login" />

    <FailureTextStyle CssClass="incorrect" />

    <SuccessTextStyle CssClass="correct" />

    <ValidatorTextStyle CssClass="incorrect" />

    </asp:ChangePassword>

    </td>

    </tr>

    </table>

    </LoggedInTemplate>

    </asp:LoginView>

    Thursday, November 20, 2008 9:09 AM
  • User1006193418 posted

     

    From my original conversion, I changed the ID to be 1 instead of 2. So my current tag is ID="CreatUserWizardStep1". Thanks for the thought, do you have anyother idea's of why it is saying that "CreatUserWizardStep1" is not declared? Thanks again! 

    Hi Thomas,

    Yes, CreateUserWizardStep1 cannot be found by the compiler in this case for the reason it is in the Template. 

    So, you may need to use Control.FindControl method to get your CreateUserWizardStep1 first. You can refer to MSDN for more information about Control.FindControl method.

    Here are the modified codes which may work for you. Have a try on it and let me if there is still any problem.

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
        'use Control.FindControl method to find the CreateUserWizardStep1 step by step
        Dim CreateUserWizard1 As CreateUserWizard
        CreateUserWizard1 = CType(LoginView1.FindControl("CreateUserWizard1"), CreateUserWizard)
        Dim CreateUserWizardStep1 As CreateUserWizardStep
        CreateUserWizardStep1 = CType(myCreateUserWizard.FindControl("CreateUserWizardStep1"), CreateUserWizardStep)
    
        'then, you can use it wherever you need
        Dim UserNameTextBox As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
        Dim DataSource As SqlDataSource = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim UserGUID As Object = User.ProviderUserKey
        DataSource.InsertParameters.Add("UserId", UserGUID.ToString())
        DataSource.Insert()
    
    End Sub
    

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 21, 2008 2:36 AM
  • User-1694337237 posted

    Hi Thomas,

    Yes, CreateUserWizardStep1 cannot be found by the compiler in this case for the reason it is in the Template. 

    So, you may need to use Control.FindControl method to get your CreateUserWizardStep1 first. You can refer to MSDN for more information about Control.FindControl method.

    Here are the modified codes which may work for you. Have a try on it and let me if there is still any problem.

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
        'use Control.FindControl method to find the CreateUserWizardStep1 step by step
        Dim CreateUserWizard1 As CreateUserWizard
        CreateUserWizard1 = CType(LoginView1.FindControl("CreateUserWizard1"), CreateUserWizard)
        Dim CreateUserWizardStep1 As CreateUserWizardStep
        CreateUserWizardStep1 = CType(myCreateUserWizard.FindControl("CreateUserWizardStep1"), CreateUserWizardStep)
    
        'then, you can use it wherever you need
        Dim UserNameTextBox As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
        Dim DataSource As SqlDataSource = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)
        Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
        Dim UserGUID As Object = User.ProviderUserKey
        DataSource.InsertParameters.Add("UserId", UserGUID.ToString())
        DataSource.Insert()
    
    End Sub
    

    Best Regards,
    Shengqing Yang

     
    Sorry for such a late response, I have been out of the office. I am now receiving an error that "myCreateUserWizard is not declared." So I changed "myCreateUserWizard" to "CreateUserWizard1." Everything seems to be running fine; however the data is not getting inserted into the table in Step 0. Any idea's?  Thanks again for all of your time!
    Monday, December 1, 2008 10:02 AM
  • User1006193418 posted

    Sorry for such a late response, I have been out of the office. I am now receiving an error that "myCreateUserWizard is not declared." So I changed "myCreateUserWizard" to "CreateUserWizard1." Everything seems to be running fine; however the data is not getting inserted into the table in Step 0. Any idea's?  Thanks again for all of your time!

    Hi,

    It seems like myCreateUserWizard should be CreateUserWizard1 in my code[:$].

    Another thing I noticed just now is there is no Hanlder statement after the Function declaration. Also, since the data is not getting inserted into the table in Step 0, I suggest you setting a breakpoint at line 9 to see if the TextBox is found by the code.

    Here is the code with the line numbers: 

    1    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
    2        Dim CreateUserWizard1 As CreateUserWizard
    3        CreateUserWizard1 = CType(LoginView1.FindControl("CreateUserWizard1"), CreateUserWizard)
    4        Dim CreateUserWizardStep1 As CreateUserWizardStep
    5        CreateUserWizardStep1 = CType(CreateUserWizard1.FindControl("CreateUserWizardStep1"), CreateUserWizardStep)
    6    
    7        'here, to set a breakpoint at the line below, then you can have a look at the TextBox's property by Qucik Watch feature in the Visual Studio
    8        Dim UserNameTextBox As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
    9        Dim DataSource As SqlDataSource = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)
    10       Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
    11       Dim UserGUID As Object = User.ProviderUserKey
    12       DataSource.InsertParameters.Add("UserId", UserGUID.ToString())
    13       DataSource.Insert()
    14   
    15   End Sub

    Best Regards,
    Shengqing Yang

     

    Thursday, December 4, 2008 10:09 PM
  • User-1694337237 posted

    Shengqing,

    First I would like to thank you for your help!

    I inserted a breakpoint at line 9 as you suggested. However I am unable to run the code due to the Handler statement; Error reads "Handles clause requires a WithEvents variable defined in the containing type or none of it's base types." I am fairly new to VB, so I am not sure how to fix this. So I would appreciate any advice!

    Thanks again for your help!

    Monday, December 8, 2008 8:45 AM
  • User1006193418 posted

    Shengqing,

    First I would like to thank you for your help!

    I inserted a breakpoint at line 9 as you suggested. However I am unable to run the code due to the Handler statement; Error reads "Handles clause requires a WithEvents variable defined in the containing type or none of it's base types." I am fairly new to VB, so I am not sure how to fix this. So I would appreciate any advice!

    Thanks again for your help!

    Hi Thomas,

    What is the name of the CreateUserWizard control in your page? In the Handles statement, we need to set the control's ID as the event handler. And in my version of code, I used the test demo, so the CreateUserWizard control 's ID was CreateUserWizard1.

    You can refer to this MSDN article for some information about the key word Handles in VB.Net: http://msdn.microsoft.com/en-us/library/6k46st1y.aspx.

    In my previouse reply, the reason why I suggested you to add the Handles key word was as you said the data was not able to be inserted in to the database, so, I doublt that the function of CreateUserWizard.CreateUser may did not fire at all. Would you please have a check on this.

    Best Regards,
    Shengqing Yang

    Tuesday, December 9, 2008 12:45 AM
  • User-1694337237 posted

    Shengqing,

    My control is named CreateUserWizard1. It is not saying that the control is not declared... It indicates that the Handles clause requires a WithEvents variable. Unfortunately, I have no idea of how to solve that.
     
     <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>For more information: When I go into create a new user I am able to complete both step's 0 and 1. The user is created, but the information for Step 0 does not get populated into the database. I do not receive any errors. (Except now with the Handles clause). <o:p></o:p>

    I am going to keep researching this issue, but if you have any other information that you can offer I would appreciate it!

    Thanks again!

    Tuesday, December 9, 2008 8:09 AM
  • User-1694337237 posted

    I have created a WithEvents tag:   The code runs with no errors; however it is still not populating the table with Step 0 Information…

    Protected WithEvents CreateUserWizard1 As CreateUserWizard

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

     

    Dim CreateUserWizard1 As CreateUserWizard

    CreateUserWizard1 = CType(LoginView1.FindControl("CreateUserWizard1"), CreateUserWizard)

    Dim CreateUserWizardStep1 As CreateUserWizardStep

    CreateUserWizardStep1 = CType(CreateUserWizard1.FindControl("CreateUserWizardStep1"), CreateUserWizardStep)

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p> 

    Dim UserNameTextBox As TextBox = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)

    Dim DataSource As SqlDataSource = CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo"), SqlDataSource)

     

    Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)

    Dim UserGUID As Object = User.ProviderUserKey

     

    DataSource.InsertParameters.Add("UserId", UserGUID.ToString())

    DataSource.Insert()

     

    End Sub<o:p></o:p><o:p> </o:p>
     

     

     

    Tuesday, December 9, 2008 8:55 AM
  • User1006193418 posted

    Hi Thomas,

    Here let's do the troubleshooting. Usually, it is caused by these two reasons that the function of a event handler doesn't work :

      1. The event handler is not fired.
      2. The code in the function has some mistakes.

    To check the first reason, we can set a break point in the function to see if the application stop at where we put it. However, to check the second one is much difficult.

    That is why I suggest you checking the former first: set a break point at the line 'DataSource.Insert()'.

    Acutally, I am still a bit confused about the error of WithEvents, which didn't occure in my test. I just double click on the CreateUser Button in the CreatUserWizard control and Visual Studio create the event handler automatically for me with the Handler statement: that is always what it works in VB.Net. Another way is to add the event handler statement in the HTML code as what C# code does.

    Well, here is another suggestion may be work:

      1. Copy the code in your CreateUserWizard1_CreatedUser function and remove them from your Code-Behind page.
      2. Goto the HTML code, double click on the CreateUser Button and paste what you copied before to the function Visaul Studio create for you automatically.

    By the way, have you done some modifications to your HTML code before? I mean, has the HTML code already been different from what you posted out in this reply: http://forums.asp.net/t/1350416.aspx#2757938?

    Best Regards,
    Shengqing Yang

    Tuesday, December 9, 2008 10:16 PM
  • User-1694337237 posted

    Shengquig,

    First of all I would like to thank you for working with me. You are right, it should have been as easy as double click on the CreateUser Button and inserting the code in the handler statement. So I decided to start all over with it and it worked!

    Again, thank you for all of your help!

    Wednesday, December 10, 2008 7:39 AM