通过从服务器调用javascript来关闭RadWindow
作者:互联网
我有一个看起来像这样的控件:
<telerik:RadCodeBlock runat="server">
<script type="text/javascript">
function refresh() {
window.$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindRecommendations");
}
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="AjaxRequest">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="NameOfGrid" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
<Windows>
<telerik:RadWindow ID="RadWindow1" runat="server" NavigateUrl="UrlOfPage" OnClientClose="refresh"></telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
页:
<script type="text/javascript">
function closeWindow() {
self.close();
return false;
}
</script>
<!-- form fields here -->
<telerik:RadButton runat="server" ID="_cancel" Text="Cancel" OnClientClick="closeWindow"></telerik:RadButton>
<telerik:RadButton runat="server" ID="_submit" Text="Submit" OnClientClick="closeWindow" OnClick="DoSomeDataBaseStuff"></telerik:RadButton>
这按预期工作.我的RadWindow被删除,我的控件的网格在点击取消或提交按钮时刷新.问题是数据库到那时还没有完成其工作,因此网格刷新不会显示更改.我试图将我的页面实现切换为如下所示:
页:
<script type="text/javascript">
function closeWindow() {
self.close();
return false;
}
</script>
<!-- form fields here -->
<telerik:RadButton runat="server" ID="_cancel" Text="Cancel" OnClick="CallJavaScriptToKillWindow"></telerik:RadButton>
<telerik:RadButton runat="server" ID="_submit" Text="Submit" OnClick="DoSomeDataBaseStuffAndThenCallJavaScriptToKillWindow"></telerik:RadButton>
Code Behind最终在数据库工作完成后调用它:
ClientScript.RegisterStartupScript(GetType(), "Key", "closeWindow();", true);
我在closeWindow函数中点击了断点,但它没有相同的行为(窗口实际上没有关闭).我尝试了各种迭代,如:
ClientScript.RegisterStartupScript(GetType(), "Key", "$(document).ready(function() {return closeWindow();});", true);
无济于事.我错过了什么?
解决方法:
什么是’自我’?你不是说’这个’吗?
您是否尝试从窗口内部或启动窗口的页面关闭RadWindow?
从窗口内部,我通常这样做:
function GetRadWindow()
{
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function Close()
{
var oWindow = GetRadWindow();
oWindow.argument = null;
oWindow.close();
return false;
}
另外,我使用ScriptManager.RegisterStartupScript而不是ClientScript.
标签:javascript,ajax,asp-net,telerik,radwindow 来源: https://codeday.me/bug/20190826/1733094.html