使用 RadButton 关闭 RadWindow

发布于 2024-12-26 08:06:18 字数 853 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独闯女儿国 2025-01-02 08:06:18

我不确定我是否正在改进这个答案,我只是想让它更容易理解。我有一个从主页打开的 rad 窗口。 radwindow 在代码隐藏 (C#) 中打开,而不是在 Javascript 中打开。当我的用户单击 RadWindow 上的“保存”按钮时,它会执行一些逻辑任务,然后关闭 radwindow 本身。您只需要:

将此代码块放入 RadWindow aspx.....

<telerik:RadCodeBlock runat="server" ID="rcb1">
<script language="javascript" type="text/javascript">

function GetRadWindow() 
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function CloseDialog(button) 
{
GetRadWindow().close();
}  

</script>
</telerik:RadCodeBlock>

执行预关闭逻辑后,将此代码放入 RadWindow 的按钮单击(执行其他逻辑的同一按钮关闭窗口)

C#
ClientScript.RegisterStartupScript(typeof(string), "", "CloseDialog();");

VB
ClientScript.RegisterStartupScript(Me.GetType(), "", "CloseDialog();")

如果您想知道如何从代码隐藏中打开 radwindow,我是这样做的:

RadWindow window1 = new RadWindow();
// Set the window properties   
window1.NavigateUrl = "winStrengthChart.aspx?EMPLOYIDNAME=" + parmString;
window1.ID = "RadWindow1";
window1.Width = 800;
window1.Height = 650;
window1.VisibleStatusbar = false;
window1.Behaviors = Telerik.Web.UI.WindowBehaviors.Close | Telerik.Web.UI.WindowBehaviors.Resize | Telerik.Web.UI.WindowBehaviors.Move;
window1.VisibleOnPageLoad = true; // Set this property to True for showing window from code   
rwm1.Windows.Add(window1);
this.Form1.Controls.Add(window1);   

...当然您需要一个基本的 RadWindowManager在打开窗口的主页上:

<telerik:RadWindowManager ID="rwm1" runat="server">
<Windows>
</Windows>
</telerik: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.....

<telerik:RadCodeBlock runat="server" ID="rcb1">
<script language="javascript" type="text/javascript">

function GetRadWindow() 
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function CloseDialog(button) 
{
GetRadWindow().close();
}  

</script>
</telerik:RadCodeBlock>

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:

RadWindow window1 = new RadWindow();
// Set the window properties   
window1.NavigateUrl = "winStrengthChart.aspx?EMPLOYIDNAME=" + parmString;
window1.ID = "RadWindow1";
window1.Width = 800;
window1.Height = 650;
window1.VisibleStatusbar = false;
window1.Behaviors = Telerik.Web.UI.WindowBehaviors.Close | Telerik.Web.UI.WindowBehaviors.Resize | Telerik.Web.UI.WindowBehaviors.Move;
window1.VisibleOnPageLoad = true; // Set this property to True for showing window from code   
rwm1.Windows.Add(window1);
this.Form1.Controls.Add(window1);   

...AND of course you need a basic RadWindowManager on the main page that opens the window:

<telerik:RadWindowManager ID="rwm1" runat="server">
<Windows>
</Windows>
</telerik:RadWindowManager>

This should work if I have made a mistake please correct me.

Thanks

予囚 2025-01-02 08:06:18

从 RadButton 调用函数的方法是使用其 OnClientClicked 或 OnClientClicking 事件。然后您只需传递 JavaScript 函数的名称,不带括号。 OnClick 是服务器处理程序的一个属性,常规的 asp 按钮也是如此。试试这个:

<telerik:RadButton ID="CancelButton" runat="server" OnClientClicked="closeWindow" AutoPostBack="false" CssClass="clicker" Text="Cancel" UseSubmitBehavior="False" EnableEmbeddedScripts="false" CausesValidation="False" RegisterWithScriptManager="False">

请注意,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:

<telerik:RadButton ID="CancelButton" runat="server" OnClientClicked="closeWindow" AutoPostBack="false" CssClass="clicker" Text="Cancel" UseSubmitBehavior="False" EnableEmbeddedScripts="false" CausesValidation="False" RegisterWithScriptManager="False">

Note the AutoPostBack property is set to false to prevent the postback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文