这种行为的原因是您ajaxTab.aspx
异步获取页面的内容并将其粘贴到另一个 aspx 页面中。因此,您将获得两个带有名称的隐藏字段实例,__VIEWSTATE
并且当页面回发到服务器时,它们的值正在混合(可能取决于浏览器如何处理多个控件,并name
在提交时使用相同的控件)。要解决此问题,您可以将第二个选项卡的内容放入框架中:
<div id="tabs">
<ul>
<li><a href="#tabs-1">Default Tab</a></li>
<li><a href="#tabs-2">ajax Content</a></li>
</ul>
<div id="tabs-1">
<p>
To replicate the error:
<ul>
<li>First use the search box top right to search to prove that code is ok</li>
<li>Then click the second ajax tab, and search again.</li>
<li>N.B. Chrome / IE give a state error, Firefox does not</li>
</ul>
</p>
</div>
<iframe id="tabs-2" src="ajaxTab.aspx" style="width:100%;" ></iframe>
</div>
另外,我不确定,但这似乎是Web_UserControls_search
控件中的错误。在我看来,NavBarSearchItemNoSearchItem_OnClick
方法必须重构如下:
protected void NavBarSearchItemNoSearchItem_OnClick(object sender, EventArgs e)
{
var searchFieldTbx = NavBarSearchItemNo;
var navBarSearchCatHiddenField = NavBarSearchCatHiddenField;
var term = searchFieldTbx != null ? searchFieldTbx.Text : "";
if (term.Length > 0) //There is actually something in the input box we can work with
{
//Response.Redirect(Url.GetUrl("SearchResults", term));
Response.Redirect(ResolveClientUrl("~/Web/SearchResults.aspx?term=" + term + "&cat=" + navBarSearchCatHiddenField.Value));
}
}
请注意我们在重定向到搜索结果页面时解析客户端 url 而不是用作navBarSearchCatHiddenField
参数。navBarSearchCatHiddenField.Value
cat