Searchbox.cs文件
protected void SearchButtonClicked()
{
Session["returnToSearch"]="/content-search-result?searchtext=test&searchmode=anyword";
Response.Redirect("/detailPage.aspx");
}
on detailPage.aspx
<a href='<%= Session["returnToSearch"] %>'>Return to Search</a>
我已经在cs文件中设置了会话,并且如果使用target_blank
重定向到在新窗口中打开的另一个页面。如果我搜索测试returnToSearch
加载前一个值,如果存储在session else空值中,但如果我重新加载页面,它将设置正确的更新值。
searchbox.aspx
<div class="search-box">
<div class="searchBox" id="SearchBox_pnlSearch">
<label style="display: none;" id="SearchBox_lblSearch" for="SearchBox_txtWord">Search for:</label>
<input type="text" class="form-control" id="SearchBox_txtWord" maxlength="1000" autocomplete="off">
<input type="submit" class="btn btn-default" id="SearchBox_btnSearch" value="Search">
<div class="predictiveSearchHolder" id="SearchBox_pnlPredictiveResultsHolder">
<div class="predictiveSearchResults" id="SearchBox" style="display: none;">
<div class="predictiveSearchCategory nonSelectable">Default Search</div>
<a onclick="return callForReturn(this);" target="_blank" href="/Art/Test-Name" style="display: block; color: black" class="selectedResult">Test Name</a>
<a onclick="return callForReturn(this);" target="_blank" href="/Art/TEst-Art" style="display: block; color: black">TEst Art</a>
<a onclick="return callForReturn(this);" target="_blank" href="/Art/Test" style="display: block; color: black">Test</a>
<a onclick="return callForReturn(this);" target="_blank" href="/Art/Test-New" style="display: block; color: black">Test New </a>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function callForReturn(obj) { $(obj).closest('.searchBox').find('input[type="submit"]').click(); }
$('.searchBox input.form-control').keyup(function (event) {
if (event.keyCode == 13) {
var getAnchor = $('.predictiveSearchResults').find('a');
$(getAnchor).attr('target', '_blank');
var getLinkUrl = $('.predictiveSearchResults').find('a.selectedResult').attr('href');
if($(getAnchor).hasClass('selectedResult')){
callForReturn(getAnchor);
var redirectWindow = window.open(getLinkUrl, '_blank');
$.ajax({
type: 'POST',
url: '/echo/json/',
success: function (data) {
redirectWindow.location;
}
});
}
}
}
</script>