我已經編寫了使用ASP.NET AJAX在更新面板中執行部分回發的SharePoint 2010可視Web部件。在Web部件內部是一個搜索功能,用戶在UpdatePanel中輸入搜索條件並觸擊Button控件,該控件查詢Web服務並將結果綁定到同一個UpdatePanel中的GridView。在數據綁定到GridView後,我想讓頁面滾動到網格的頂部。在AJAX UpdatePanel回發後滾動到SharePoint Visual Web部件上的位置
標記(縮寫):
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" EnableViewState="true">
<ProgressTemplate>
<div id="progressBackgroundFilter"></div>
<div id="processMessage">
<h1>Processing<img src="/_layouts/WebPart/ajax-loader.gif" alt="" /></h1>
</div>
</ProgressTemplate>
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" Visible="true" ValidationGroup="SearchGroup" />
<asp:GridView ID="InstancesGrd" runat="server" Visible="false" AutoGenerateColumns="false" OnRowCommand="InstancesGrd_RowCommand" GridLines="Vertical" BorderColor="White" CssClass="grid">
</asp:GridView>
</asp:UpdatePanel>
代碼隱藏(縮寫):
protected void btnSearch_Click(object sender, EventArgs e)
{
ServiceClient client = ConfigureServiceProxy();
List<string> data = client.returnResults();
InstancesGrd.DataSource = data;
InstancesGrd.DataBind();
InstancesGrd.Visible = true;
}
JavaScript代碼:
<script type="text/javascript">
_spOriginalFormAction = document.forms[0].action;
_spSuppressFormOnSubmitWrapper = true;
</script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
function pageLoad() {
$('.leftItem').hover(
function() {
$('ul', this).css('display', 'block');
$(this).css('background-image', 'url("_layouts/testclientwebpart/leftNavHover.gif")');
},
function() {
$('ul', this).css('display', 'none');
$(this).css('background-image', 'url("_layouts/testclientwebpart/navBarLeft.gif")');
}
);
$('.rightItem').hover(
function() {
$('ul', this).css('display', 'block');
$(this).css('background-image', 'url("_layouts/testclientwebpart/rightNavHover.gif")');
},
function() {
$('ul', this).css('display', 'none');
$(this).css('background-image', 'url("_layouts/testclientwebpart/navBarRight.gif")');
}
);
$('.middleItem').hover(
function() {
$('ul', this).css('display', 'block');
$(this).css('background-image', 'url("_layouts/testclientwebpart/middleNavHover.gif")');
},
function() {
$('ul', this).css('display', 'none');
$(this).css('background-image', 'url("_layouts/testclientwebpart/navBarMiddle.gif")');
}
);
}
Sys.WebForms.PageRequestManager.getInstance()add_beginRequest(。的BeginRequest); Sys.WebForms.PageRequestManager.getInstance()。add_pageLoaded(pageLoaded);
function beginRequest(sender, args) {
postbackElement = args.get_postBackElement();
}
function pageLoaded(sender, args) {
if (typeof (postbackElement) === "undefined") {
return;
}
if ((postbackElement.id) === "ctl00_SPWebPartManager1_g_d2fd9460_f326_4df6_92c5_7afd7da02faa_ctl00_btnSearch") {
//--- Scroll test -- does not work
window.scrollTo(750, 0);
}
}
</script>
我使用ClientScriptManager.RegisterStartupScript在服務器端和PageRequestManager.getInstance()嘗試。add_beginRequest()和add_pageLoaded()的JavaScript事件處理程序添加到按鈕的onclick客戶端功能。我能夠觸發來自兩者的警報,但無法重置滾動位置。
我錯過了什麼嗎?
無法重置滾動位置意味着什麼? – Dolo
滾動條在超過窗口高度的頁面上的位置。 – maniak1982