4
私はasp.netサイトでMicrosoft Visual Basic 2010を使用しています。ユーザーがログインしていることを確認してください
ユーザー登録にasp.net構成を使用しています。
私は今、私が欲しいものを正確に行うログインビューと呼ばれるツールボックスヘルパーがありますが、コードの中にフォームを置くとすぐに表示されます。テキストボックスフィールドが見つからないためコンパイルされません。
私はNewsArticle.aspxに次があります。NewsArticle.aspx.csオン
<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>
私が持っている:
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));
}
私はASPの外形をとる場合: LoginViewそれはうまく動作します。
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
ありがとう:
あなたはこれらのコントロールを配置するためにFindControlメソッドを使用する必要があります。私は以下を試しました: ta.Insert1(articleid、gUser.ToString()、LoginView.FindControl(txtTitle).Text、oginView.FindControl(txtComment).Text); これは同じエラーを示しています。 – daveredfern
実際のコードとエラーメッセージを指定できますか。 LoginView1.FindControl( "txtComment") これが失敗した場合、エラーメッセージはNullreference例外である必要があります。 –
私には次のものがあります。 LoginView1.FindControl(txtTitle).Text。 エラー: エラー2名前 'txtTitle'が現在のコンテキストに存在しません\t NewsArticle.aspx.cs 59 76 Figmentville – daveredfern