在 kentico 中使用 response.write 重定向 html 表单不起作用
redirecting a html form using response.write in kentico not working
我试图 post 一个 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>
但是没有发送,
以下是通过单击按钮访问的表单构建/发送的片段:
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();
}
- 只要搜索一下,这个问题已经很多了
- 您在 NEW_ITEM...
上遗漏了结束语
- 第三次使用 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>
我没有提到我的代码在 ascx 页面中,我将我的代码移动到 aspx 页面并且 response.write 现在将表单数据发送到外部 URL。
我试图 post 一个 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>
但是没有发送,
以下是通过单击按钮访问的表单构建/发送的片段:
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();
}
- 只要搜索一下,这个问题已经很多了
- 您在 NEW_ITEM...
- 第三次使用 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>
我没有提到我的代码在 ascx 页面中,我将我的代码移动到 aspx 页面并且 response.write 现在将表单数据发送到外部 URL。