Check if user is registered

I am using Microsoft Visual Basic 2010 for asp.net using C #.

I am using asp.net configuration to register a user. I have a comment form that I want to show only if the user is registered.

Now I have a helper thing for the tool called Login View, which does exactly what I want, but as soon as I pasted the form inside the code, it will not compile because it cannot find the text field fields.

I have the following in NewsArticle.aspx:

<asp:LoginView ID="LoginView1" runat="server"> <AnonymousTemplate> <div class="postcomment"> <p><a href="/account/Login.aspx">Login</a> or <a href="/account/Register.aspx">register</a> to post a comment.</p> </div> </AnonymousTemplate> <LoggedInTemplate> <div class="formcomment"> <asp:TextBox ID="txtTitle" textMode="SingleLine" runat="server"></asp:TextBox> <asp:TextBox ID="txtComment" TextMode="MultiLine" runat="server"></asp:TextBox> <asp:Button ID="cmdUpdate" runat="server" Text="Add Comment" onclick="cmdUpdate_Click" /> </div> </LoggedInTemplate> 

In NewsArticle.aspx.cs, I have:

 protected void cmdUpdate_Click(object sender, EventArgs e) { // Get user id Guid gUser; MembershipUser user = Membership.GetUser(Page.User.Identity.Name); gUser = (Guid)user.ProviderUserKey; // get article id int articleid = Convert.ToInt16(Request.QueryString["id"]); // Add to db FrontendTableAdapters.NewsCommentTableAdapter ta = new FrontendTableAdapters.NewsCommentTableAdapter(); ta.Insert1(articleid, gUser.ToString(), txtTitle.Text, txtComment.Text); // Redirect back to article Response.Redirect(String.Format("NewsArticle.aspx?id={0}#comments", articleid)); } 

If I select a form from asp: LoginView, it works fine. Inside I get the following:

 Error 2 The name 'txtTitle' does not exist in the current context NewsArticle.aspx.cs 59 53 Figmentville Error 3 The name 'txtComment' does not exist in the current context \NewsArticle.aspx.cs 59 68 Figmentville 
+4
source share
1 answer

You cannot directly access txtTitle and txtComment.

They should be accessed through the LoginView control because they are contained in it.

To find these controls, use the FindControl method: LoginView.FindControl (stringId)

+2
source

All Articles