'firstName' is not declared. It may be inaccessible due to its protection level.

Member_2_5230414
Member_2_5230414 used Ask the Experts™
on
For some reason its not picking up the textbox text. i get the error "'firstName' is not declared. It may be inaccessible due to its protection level." but i thought i don't need to declare the textbox?

 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="signup.aspx.vb" Inherits="freelance_site_memberslogin_signup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:CreateUserWizard ID="CreateUserWizard1" oncreateduser="CreateUserWizard1_CreatedUser" RequireEmail="false" runat="server">
        <WizardSteps>
            <asp:CreateUserWizardStep runat="server">
                <ContentTemplate>
                    <table>
                        <tr>
                            <td align="center" colspan="2">
                                Sign Up for Your New Account</td>
                        </tr>
                        <tr>
                            <td align="right">
                                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                            </td>
                            <td>
                                <asp:UpdatePanel runat="server" ID="up1">
  <ContentTemplate>
   <asp:TextBox runat="server" id="Username" 
    AutoPostBack="true" /><br />
  </ContentTemplate>
</asp:UpdatePanel>
                                  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="UserName" ErrorMessage="Please enter a valid email address." SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

                            </td>
                        </tr>

                        <tr>
                  <td align="right">
                    First name:</td>
                  <td>
                    <asp:textbox id="firstName" runat="server" /></td>
                </tr>
                <tr>
                  <td align="right">
                    Last name:</td>
                  <td>
                    <asp:textbox id="lastName" runat="server" /></td>
                </tr>
                        <tr>
                            <td align="right">
                                <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" ErrorMessage="Password is required." 
                                    ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <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" 
                                    ErrorMessage="Confirm Password is required." 
                                    ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2">
                                <asp:CompareValidator ID="PasswordCompare" runat="server" 
                                    ControlToCompare="Password" ControlToValidate="ConfirmPassword" 
                                    Display="Dynamic" 
                                    ErrorMessage="The Password and Confirmation Password must match." 
                                    ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2" style="color:Red;">
                                <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep runat="server" />
        </WizardSteps>
    </asp:CreateUserWizard>

    </form>
</body>
</html>
                                  

Open in new window



code behind

Partial Class freelance_site_memberslogin_signup
    Inherits System.Web.UI.Page
    Public Sub RegisterNewUser_CreatingUser(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cuw As CreateUserWizard = DirectCast(sender, CreateUserWizard)
        cuw.Email = cuw.UserName
    End Sub
    Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs)
        Profile.SetPropertyValue("userName", firstName.Text & " " & lastName.Text)
    End Sub


   
End Class

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Because it is in a template you have to use FindControl
Dim Name As String = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("firstName"), TextBox).Text

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial