Hi,
I am trying to make a Contact form exclusive for Members. So as my first field (ID=username) I would like some VB script so that when the page loads it can identify the user that is accessing the page and display it in a read-only text ready for submission by email (with the email address and text area, don't worry about these because I know how to add these).
Any help will be greatly appreciated.
(here is my Contact us page code, nothing special but I'll give you it just in case)
Code:
- <%@ Page Title="" Language="VB" MasterPageFile="~/Members/MasterMembers.master" AutoEventWireup="false" CodeFile="MembersCustomerSupport.aspx.vb" Inherits="Contact_Us_MembersCustomerSupport" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> </SPAN>
- <div class="alldivs"> </SPAN>
- <asp:LoginView ID="LoginView1" runat="server"> </SPAN>
- <AnonymousTemplate> </SPAN>
- <p>You must be a Member to benefit from our Member's customer services.</p> </SPAN>
- </AnonymousTemplate> </SPAN>
- <LoggedInTemplate> </SPAN>
- <h1>Members' Customer Support </h1> </SPAN>
- <p>Please fill in all the required fields:</p> </SPAN>
- <table border="0" style="width: 565px"> </SPAN>
- <tr> </SPAN>
- <td style="width: 95px"> </SPAN>
- <p> </SPAN>
- User Name</p> </SPAN>
- </td> </SPAN>
- <td width="455"> </SPAN>
- <p> </SPAN>
- <label> </SPAN>
- </label> </SPAN>
- <asp:TextBox ID="username" runat="server" ReadOnly="True" </SPAN>
- ToolTip="The field is uneditable"></asp:TextBox> </SPAN>
- <asp:LoginName ID="LoginName1" runat="server" /> </SPAN>
- </p> </SPAN>
- </td> </SPAN>
- </tr> </SPAN>
- <tr> </SPAN>
- <td style="width: 95px"> </SPAN>
- <p> </SPAN>
- Email</p> </SPAN>
- </td> </SPAN>
- <td> </SPAN>
- <p> </SPAN>
- <label> </SPAN>
- </label><asp:TextBox ID="email" runat="server"></asp:TextBox> </SPAN>
- <asp:RegularExpressionValidator </SPAN>
- ID="RegularExpressionValidator1" runat="server" </SPAN>
- ErrorMessage="Your Email is required" </SPAN>
- ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" </SPAN>
- ControlToValidate="email"></asp:RegularExpressionValidator> </SPAN>
- </p> </SPAN>
- </td> </SPAN>
- </tr> </SPAN>
- <tr> </SPAN>
- <td style="width: 95px"> </SPAN>
- <p> </SPAN>
- Message</p> </SPAN>
- </td> </SPAN>
- <td> </SPAN>
- <p> </SPAN>
- <label> </SPAN>
- </label><asp:TextBox ID="message" runat="server" TextMode="MultiLine"></asp:TextBox> </SPAN>
- <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" </SPAN>
- ErrorMessage="A message is required" ControlToValidate="message" </SPAN>
- Display="Dynamic"></asp:RequiredFieldValidator> </SPAN>
- </p> </SPAN>
- </td> </SPAN>
- </tr> </SPAN>
- </table> </SPAN>
- <p> </SPAN>
- <label> </SPAN>
- <input ID="Submit" name="Submit" type="submit" value="Submit"> </input></label> </SPAN>
- </p> </SPAN>
- </LoggedInTemplate> </SPAN>
- </asp:LoginView> </SPAN>
- </div> </SPAN>
- </asp:Content> </SPAN>
I have tried to add the following into the VB script code so that the read-only text equals the current logged in user.
However when I load the page it tells me that, "username has not been declared" even though it is the ID of my texbox:
Code:
PartialClass Contact_Us_MembersCustomerSupport
Inherits System.Web.UI.Page
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
username.Text = User.Identity.Name
EndSub
EndClass
Thanks guys
|