我在这里找到了一个阻止我网页一部分的很好的例子。
但是我已经尝试了几个小时来使我的UserControl适应此示例,但没有任何进展。可能是因为我对JQuery和 ASP.Net 还不太熟悉。例如,我不明白prm.add_beginRequest
和prm.add_endRequest
做什么以及这个页面请求管理器是什么。
所以我想问一下这里的专家,如果你能解决我的问题:
我有一个 ASP.Net 用户控件,上面有一个网格(telerik RadGrid)。在顶部,我有一个保存按钮("btnSave")。单击按钮时,服务器会将数据保存到文件中。目前为止,一切都好。但与此同时,我想用示例中的漂亮条块阻止这个网格。
谁能告诉我如何调整我的用户控件,以便在服务器准备就绪之前阻止网格(和按钮)?
这是我到目前为止的ExcelGrid.ascx文件:
<%@ Control Language="C#" AutoEventWireup="True" Codebehind="ExcelGrid.ascx.cs" className="ExcelGrid" Inherits="WebResourceEditor.UI.Main.RightContent.ExcelGrid" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link href="/Styles/Styles.css" rel="Stylesheet" />
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
var radGridId = "<%=mainDataGrid.ClientID %>";
</script>
</telerik:RadCodeBlock>
<style type="text/css">
html body span .rinSingle .riTextBox .RadInput .RadInput_Default
{
width: 100% !important;
}
</style>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
<script src="/Scripts/script.js" type="text/javascript"></script>
<script src = "/Scripts/jquery.blockUI.js" type = "text/javascript"></script>
<telerik:RadScriptBlock runat="server" ID="RadScriptBlock2">
<script type="text/javascript">
function RowContextMenu(sender, eventArgs) {
var menu = window.$find("<%=RadMenu1.ClientID %>");
var evt = eventArgs.get_domEvent();
var index = eventArgs.get_gridDataItem().get_element().id.split("__")[1];
document.getElementById("<%=radGridClickedRowIndex.ClientID %>").value = index;
sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
menu.show(evt);
evt.cancelBubble = true;
evt.returnValue = false;
if (evt.stopPropagation) {
evt.stopPropagation();
evt.preventDefault();
}
}
function GridCreated(sender, args) {
var scrollArea = sender.GridDataDiv;
var parent = window.$get("gridContainer");
var gridLabel = window.$get("gridLabel");
var gridMenuBar = window.$get("gridMenuBar");
var gridHeader = sender.GridHeaderDiv;
scrollArea.style.height = parent.clientHeight - gridHeader.scrollHeight
- gridMenuBar.scrollHeight - gridLabel.scrollHeight - 1 + "px";
}
function BlockUI(elementID) {
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(function () {
$("#" + elementID).block({ message: '<table align = "center"><tr><td>' +
'<img src="/Images/loadingAnim.gif"/></td></tr></table>',
css: {},
overlayCSS: { backgroundColor: '#000000', opacity: 0.6, border: '3px solid #63B2EB'
}
});
});
prm.add_endRequest(function () {
$("#" + elementID).unblock();
});
}
$(document).ready(function () {
BlockUI("gridContainer");
$.blockUI.defaults.css = {};
});
</script>
</telerik:RadScriptBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="mainDataGrid">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="mainDataGrid" LoadingPanelID="RadAjaxLoadingPanel1">
</telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="RadMenu1"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadMenu1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="mainDataGrid" LoadingPanelID="RadAjaxLoadingPanel1">
</telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="RadMenu1"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<asp:HiddenField ID="radGridClickedRowIndex" runat="server" />
<div id="gridContainer" style="height:100%;">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div id="gridLabel">
<asp:Label ID="fileNameTextEdit" style="padding: 2px 5px;"
Text="No Project Folder or Resource File Group selected" runat="server" />
<br/>
</div>
<telerik:RadGrid ID="mainDataGrid" OnNeedDataSource="mainDataGrid_NeedDataSource" OnPreRender="RadGrid1_PreRender"
Skin="Default" OnItemDataBound="RadGrid1_ItemDataBound" OnColumnCreated="mainDataGrid_ColumnCreated"
AllowMultiRowEdit="true" EnableLinqExpressions="false"
OnItemCommand="RadGrid1_ItemCommand"
runat="server">
<MasterTableView EditMode="InPlace" CommandItemDisplay="Top"
DataKeyNames="FileGroup,Name">
<CommandItemTemplate>
<div id="gridMenuBar" style="padding: 5px 5px;">
<asp:LinkButton ID="btnSave" runat="server" CommandName="Save">
<img style="border:0px;vertical-align:middle;" alt="" src="/Images/RightContent/popupImages/image01.png" />Save in Database</asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" OnClientClick="DiscardChanges(this, event);"
CommandName="Discard Changes">
<img style="border:0px;vertical-align:middle;" alt="" src="/Images/icons/16/image25.png" />Discard Changes</asp:LinkButton>
</div>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" ReadOnly="true" />
</Columns>
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="true" ScrollHeight="500px" UseStaticHeaders="true" />
<ClientEvents OnRowContextMenu="RowContextMenu"/>
<ClientEvents OnGridCreated="GridCreated" />
</ClientSettings>
</telerik:RadGrid>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<telerik:RadContextMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick"
OnClientItemClicking="RadMenu1_ItemClicking" EnableRoundedCorners="true" EnableShadows="true"
OnClientLoad="MenuLoad">
<Items>
<telerik:RadMenuItem Text="Save" AccessKey="S">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Discard Changes" AccessKey="C">
</telerik:RadMenuItem>
</Items>
</telerik:RadContextMenu>
如您所见,我正在使用 Telerik 控件。我设法使用RadAjaxLoadPanel阻止了我的网格。有关更多信息,请参阅此处。
是的,Telerik 有这样的控件来显示加载面板。这里
此外,如果刷新数据的时间太短,则有可能看到闪烁。
为避免这种情况,您可以使用"最小显示时间"添加加载面板应显示的最短时间(以毫秒为单位)。