使用 RadButton 关闭 RadWindow
我正在尝试使用 RadButton 来关闭窗口本身的 radwindow(通过 javascript)。是否可以调用脚本来关闭窗口?这是 javascript:
function getRadWindow()
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function closeWindow()
{
getRadWindow().close();
}
这是按钮:
<telerik:RadButton ID="CancelButton" runat="server" OnClick="closeWindow();" CssClass="clicker" Text="Cancel" UseSubmitBehavior="False" EnableEmbeddedScripts="false" CausesValidation="False" RegisterWithScriptManager="False">
</telerik:RadButton>
我已经尝试了一切,只有当我使用纯 HTML 元素(例如锚标记)时,该脚本才会起作用。如果我使用 OnClick 事件,当窗口打开时,我会收到以下错误:编译器错误消息:CS1026:)预期。
我错过了什么吗?
谢谢!
I'm trying to use a RadButton to close a radwindow from with the window itself (via javascript). Is it possible to call a script to close the window? Here is the javascript:
function getRadWindow()
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function closeWindow()
{
getRadWindow().close();
}
And here is the button:
<telerik:RadButton ID="CancelButton" runat="server" OnClick="closeWindow();" CssClass="clicker" Text="Cancel" UseSubmitBehavior="False" EnableEmbeddedScripts="false" CausesValidation="False" RegisterWithScriptManager="False">
</telerik:RadButton>
I have tried everything, the script will only work if I use a pure HTML element such as an anchor tag. If I use the OnClick event I get the following error when the window opens: Compiler Error Message: CS1026: ) expected.
Am I missing something?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否正在改进这个答案,我只是想让它更容易理解。我有一个从主页打开的 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
从 RadButton 调用函数的方法是使用其 OnClientClicked 或 OnClientClicking 事件。然后您只需传递 JavaScript 函数的名称,不带括号。 OnClick 是服务器处理程序的一个属性,常规的 asp 按钮也是如此。试试这个:
请注意,AutoPostBack 属性设置为 false 以防止回发。
The way to call a function from the RadButton is by using either its OnClientClicked or OnClientClicking event. Then you need to pass only the name of the JavaScript function, without parenthese. OnClick is a property for the server handler, this is also the case with the regular asp button. Try this:
Note the AutoPostBack property is set to false to prevent the postback.