通过从服务器调用 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>
Page:
<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>
代码隐藏在数据库工作完成后最终会调用此:
ClientScript.RegisterStartupScript(GetType(), "Key", "closeWindow();", true);
我在 closeWindow 函数中遇到了断点,但它没有相同的行为(窗口没有实际上很接近)。我尝试过各种迭代,例如:
ClientScript.RegisterStartupScript(GetType(), "Key", "$(document).ready(function() {return closeWindow();});", true);
无济于事。我缺少什么?
I have a Control that looks like this:
<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>
Page:
<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>
This works as intended. My RadWindow is removed and my control's grid refreshes upon hitting either the cancel or submit buttons. The problem is that the database isn't finished doing its work by that time so the grid refresh doesn't reveal the changes. I have attempted to switch my implementation of page to look like this:
Page:
<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 eventually calls this after database work completes:
ClientScript.RegisterStartupScript(GetType(), "Key", "closeWindow();", true);
I hit my breakpoint in the closeWindow function, but it doesn't have the same behavior (the window doesn't actually close). I've tried various iterations like:
ClientScript.RegisterStartupScript(GetType(), "Key", "$(document).ready(function() {return closeWindow();});", true);
to no avail. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
什么是‘自我’?你不是说‘这个’吗?
您是否尝试从窗口内部或启动窗口的页面关闭 RadWindow?
在窗口内部,我通常这样做:
此外,我会使用 ScriptManager.RegisterStartupScript 而不是 ClientScript。
What is 'self'? Don't you mean 'this'?
Are you trying to close the RadWindow from inside the window or from the page that launches the window?
From inside a window, I usually do this:
Also, I'd use ScriptManager.RegisterStartupScript rather than ClientScript.
我很确定我以前遇到过这个问题,并且我认为这已经解决了:
如果这不起作用,请尝试以下操作:
如果您愿意,也可以这样做:
I'm pretty sure that I've run into this issue before, and I think this fixed it:
If that doesn't work, try this:
You can also do it this way if you'd prefer:
我不确定我是否正在改进这个答案,我只是想让它更容易理解。我有一个从主页打开的 rad 窗口。 radwindow 在代码隐藏 (C#) 中打开,而不是在 Javascript 中打开。当我的用户单击 RadWindow 上的“保存”按钮时,它会执行一些逻辑任务,然后关闭 radwindow 本身。您只需要:
将此代码块放入 RadWindow aspx.....
执行预关闭逻辑后,将此代码放入 RadWindow 的按钮单击(执行其他逻辑的同一按钮关闭窗口)
C#
ClientScript.RegisterStartupScript(typeof(string), "", "CloseDialog();");
或
VB
ClientScript.RegisterStartupScript(Me.GetType(), "", "CloseDialog();")
如果您想知道如何从代码隐藏中打开 radwindow,我是这样做的:
...当然您需要一个基本的 RadWindowManager在打开窗口的主页上:
这应该可以工作,如果我犯了错误,请纠正我。
谢谢
I'm not sure if I am improving this answer, I'm just trying to make it easier to understand. I have a rad window that is opened from a main page. The radwindow is opened in Code Behind (C#), not Javascript. When my user clicks a Save button on the RadWindow, it performs some logic tasks, then it closes the radwindow itself. You simply need to:
Put thise code block in you RadWindow aspx.....
Put this code in your RadWindow's button click after you perform your pre-close logic (the same button that performs the other logic closes the window)
C#
ClientScript.RegisterStartupScript(typeof(string), "", "CloseDialog();");
OR
VB
ClientScript.RegisterStartupScript(Me.GetType(), "", "CloseDialog();")
If you're wondering how to open the radwindow from codebehind here is how I did it:
...AND of course you need a basic RadWindowManager on the main page that opens the window:
This should work if I have made a mistake please correct me.
Thanks