0

I'd like to prepopulate my textfield with the following variable:

<%=Membership.GetUser().Email%> 

... so that users can submit their email address to my table without having to type it in.

Here is my code:

<form id="form1" runat="server">
    <div>
        <!-- This is the code for the form. There is a Text Box to collect the first name, 
            last name and email address. All fields are required and I am validating that the 
            email address is a valid format. -->
        <asp:Table ID="Table1" runat="server">
            <asp:TableRow>
                <asp:TableCell>First Name: <asp:TextBox ID="txtFirstName" 
                    runat="server" Width="60" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
                    ErrorMessage="Enter First Name" Text="*" ControlToValidate="txtFirstName" 
                    runat="server" />
                </asp:TableCell>
                <asp:TableCell>Last Name: <asp:TextBox ID="txtLastName" runat="server" Width="60" /> 
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ControlToValidate="txtLastName" ErrorMessage="Enter Last Name" Text="*" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>Email: <asp:TextBox ID="txtEmail" runat="server" Width="80" />
                    <asp:RequiredFieldValidator ID="emailRequired" 
                        runat="server" ControlToValidate="txtEmail" ErrorMessage="Email Needs Information" 
                        Text="*"/>
                    <asp:RegularExpressionValidator ID="emailexpression" 
                        runat="server" ControlToValidate="txtEmail" ValidationExpression=".*@.*\..*" 
                        ErrorMessage="Invalide Email Address" Text="*" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="true" 
                        ShowMessageBox="true" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell><asp:Button ID="btnSubmit" runat="server" OnClick="addMember" 
                    CausesValidation="true" Height="30" Width="100" Text="Add Me" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    <asp:Label ID="lblDuplicate" runat="server" Text=""></asp:Label>
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
</form>

How can I accomplish this?

1
  • So, what exactly are you having an issue with? Commented Oct 5, 2010 at 16:00

1 Answer 1

1

Pop it in the page load event in the code-behind?

if (!Page.IsPostBack)
{
    txtEmail.Text = Membership.GetUser().Email;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.