The reason of such behavior is that you getting content of the ajaxTab.aspx
page asynchronously and paste it into another aspx page. So you getting two instances of hidden fields with __VIEWSTATE
name and when page posted back to server theirs values are mixing (might depends on how browser process multiple controls with same name
on submit). To resolve this you can put second tab's content into a frame:
<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>
Also, I'm not sure but this seems like error in the Web_UserControls_search
control. In my opinion, NavBarSearchItemNoSearchItem_OnClick
method must be refactored as below:
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));
}
}
Draw attention that we resolving client url when redirecting to search results page and instead of navBarSearchCatHiddenField
use navBarSearchCatHiddenField.Value
as cat
parameter.