【问题标题】:error with form action表单操作错误
【发布时间】:2013-03-20 21:06:14
【问题描述】:

我有以下 C# 代码:

 AddCommentForm = string.Format("<form name=\"AddComment\" method=\"post\"  runat=\"server\" id=\"add_comment_form\"><p> TITLE:  <input type =\"text\" name=\"Title\" /></p><p> Contnt <textarea name=\"Content\" ></textarea></p><p> <button type=\"submit\">Submit!</button></p></form>");
                this.Form.Action = "ViewArticle.aspx?ArticleID=" + ArticleID;

问题是第二行有错误:

System.NullReferenceException was caught

我的问题是我怎么会出现这个错误?

为什么使用这段代码可以工作?

 <%
     this.Form.Action = "ViewArticle.aspx?ArticleID=" + ArticleID.ToString();
 %>
 <form name="AddComment"  method="post" runat="server">

【问题讨论】:

标签: asp.net forms webforms action nullreferenceexception


【解决方案1】:
AddCommentForm = string.Format("<form name=\"AddComment\" method=\"post\" ....

以上代码无效。 AddCommentForm 是一个 HtmlForm 控件 - 不是字符串。此外,您不能在 ASP.Net 中的表单内创建另一个 form 标签。

this.Form.Action = "ViewArticle.aspx?ArticleID=" + ArticleID.ToString();

基本上,你是Cross-Site Scripting。虽然它编译,但它不会工作。当你到达ViewArticle.aspx页面时,你会得到一个错误。

如果您想在 ASP.Net 中使用表单,请使用 iframe。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多