I`ve got a link in a Webforms page which opens in a new window, and posts to a form other than the page itself. This is done like this:
我在一个新窗口打开的Webforms页面中有一个链接,并将它发布到页面本身之外的表单。这是这样做的:
JS:
JS:
var submitFunc = function(){
document.forms[0].action = 'http://urlToPostTo/somePage.aspx';
document.forms[0].target = '_blank';
document.forms[0].submit();
}
The link:
链接:
<input type="hidden" id="myDataId" value="12345" />
<a href="javascript:submitFunc();">Search</a>
As you can see, this overrides the target of the main <form>
, and attempts to post to a different page. The whole point is that this should post/submit to a different page, while avoiding passing the data of "myDataId" as a Get parameter.
如您所见,这将覆盖主
The above code would work, but causes an error due to viewstate validation.
上面的代码可以工作,但是由于viewstate验证导致了一个错误。
Question: Is there any way for me to either satisfy the requirements here, or somehow bypass the viewstate validation so I can post my data this way?
问:我是否有办法满足这里的需求,或者绕过viewstate验证,以便以这种方式发布数据?
1 个解决方案
#1
1
Sounds like you just need to change the PostBackUrl
of the button that submits the form.
听起来您只需更改提交表单的按钮的PostBackUrl。
A simple example PostToPage1.aspx that posts to PostToPage2.aspx (instead of a postback):
一个简单的例子PostToPage1。发送到PostToPage2的aspx。aspx(不是回邮):
<form id="form1" runat="server">
<div>
<asp:TextBox ID="text1" runat="server" /><br />
<asp:TextBox ID="text2" runat="server" />
<asp:Button ID="btn1" runat="server" PostBackUrl="~/PostToPage2.aspx" />
</div>
</form>
You can then inspect the Request
in PostToPage2.aspx
to check if it's a POST, etc. and then access the Request.Form
collection in the Request
in Page_Load
.
然后可以在PostToPage2中检查请求。aspx检查它是否是POST,等等,然后访问请求。在Page_Load中的请求中的表单集合。
An overly simplified sample for PostToPage2.aspx (do add proper validation):
PostToPage2的一个过于简化的示例。aspx(添加适当的验证):
if (!Page.IsPostBack && Request.RequestType == "POST")
{
if (Request.Form != null && Request.Form.Keys.Count > 0)
{
.....
Hth...
Hth……
#1
1
Sounds like you just need to change the PostBackUrl
of the button that submits the form.
听起来您只需更改提交表单的按钮的PostBackUrl。
A simple example PostToPage1.aspx that posts to PostToPage2.aspx (instead of a postback):
一个简单的例子PostToPage1。发送到PostToPage2的aspx。aspx(不是回邮):
<form id="form1" runat="server">
<div>
<asp:TextBox ID="text1" runat="server" /><br />
<asp:TextBox ID="text2" runat="server" />
<asp:Button ID="btn1" runat="server" PostBackUrl="~/PostToPage2.aspx" />
</div>
</form>
You can then inspect the Request
in PostToPage2.aspx
to check if it's a POST, etc. and then access the Request.Form
collection in the Request
in Page_Load
.
然后可以在PostToPage2中检查请求。aspx检查它是否是POST,等等,然后访问请求。在Page_Load中的请求中的表单集合。
An overly simplified sample for PostToPage2.aspx (do add proper validation):
PostToPage2的一个过于简化的示例。aspx(添加适当的验证):
if (!Page.IsPostBack && Request.RequestType == "POST")
{
if (Request.Form != null && Request.Form.Keys.Count > 0)
{
.....
Hth...
Hth……