【问题标题】:redirecting a html form using response.write in kentico not working在kentico中使用response.write重定向html表单不起作用
【发布时间】:2016-03-17 12:18:11
【问题描述】:

我尝试将 HTML 表单发布到另一个 URL,在我的测试中创建了表单:

<html>
<body onload='document.forms["form1"].submit()'>
<form id='form1' method='POST' action='http://localhost:52035/testpage?'>
<input type='hidden' id='name' value='form1' />
<input type='hidden' name='NEW_ITEM["0"] value='1234-ABC'/>
</form>
</body>
</html>

但不发送,

以下是 build / send 形式的 sn-p,可通过单击按钮访问:

protected void btnSubmitRequest_Click(object sender, EventArgs e)
        {
var hookUrl = SessionHelper.GetValue("hookurl").ToString();
string formId = "form1";
StringBuilder htmlForm = new StringBuilder();
htmlForm.AppendLine("<html>");
htmlForm.AppendLine(String.Format("<body onload='document.forms[\"{0}\"].submit()'>", formId));
htmlForm.AppendLine(String.Format("<form id='{0}' method='POST' action='{1}'>", formId, hookUrl));
htmlForm.AppendLine("<input type='hidden' id='name' value='form1' />");
// test values 
prod.ProductCode = "1234-ABC"
int i = 0;

htmlForm.AppendLine(String.Format("<input type='hidden' name='NEW_ITEM[\"{0}\"] value='{1}'/>",i, prod.ProductCode));
htmlForm.AppendLine("</form>");
                        htmlForm.AppendLine("</body>");
                        htmlForm.AppendLine("</html>");

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(htmlForm.ToString());
HttpContext.Current.ApplicationInstance.CompleteRequest();

}

【问题讨论】:

  • 您的表单没有name="form1"
  • 哦,那应该在 &lt;form&gt; 加载后执行。
  • 嗨 Paveen,我添加了 name='form1',您是说 htmlForm 行“”需要更改吗?
  • 没有哥们,onload&lt;form&gt; 没看到。
  • 添加name='form1'后,还是不行。

标签: javascript c# asp.net http-post kentico


【解决方案1】:
  • 如果你只是搜索它们,这个问题已经很多了
  • 您错过了 NEW_ITEM 的结束报价...
  • 第 3 次使用 Ajax + FormData 而不是乱用 html。

这是解决您问题的可能方法

<body>
  <form id='form1' name='form1' method='POST' action='http://localhost'>
    <input type='text' id='name' value='form1'>
    <input type='text' name='NEW_ITEM["0"]' value='1234-ABC'>
  </form> 
  <script>document.forms.form1.submit()</script>
</body>

【讨论】:

    【解决方案2】:

    我没有提到我的代码在 ascx 页面中,我将我的代码移到了 aspx 页面,response.write 现在将表单数据发送到外部 URL。

    【讨论】:

    • 已解决。我现在将数据发送到页面后面的 aspx 代码,然后构建表单并从那里发布。
    猜你喜欢
    • 1970-01-01
    • 2013-12-02
    • 2014-03-07
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多