javascript RadWindow:从 C# 打开窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6019932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:10:20  来源:igfitidea点击:

RadWindow: Opening windows from C#

javascriptvisual-studio-2010buttontelerikradwindow

提问by G18Programmer

Need to open a webpage in a radWindow from a button click event. Attempted to do this from client side but, it appears and then immediately disappears. I Think the button click is causing a postback to the server... Therefore, I'm currently attempting to solve this issue with server side code (C#) posted below.

需要通过按钮单击事件在 radWindow 中打开网页。试图从客户端执行此操作,但它出现然后立即消失。我认为单击按钮会导致回发到服务器...因此,我目前正在尝试使用下面发布的服务器端代码 (C#) 解决此问题。

Problem: Need to open rad windows without adding them to the window collection or remove them from the window collection on close. They aren't being removed from the window collection on closing of the rad window. This results in the same window opening for the number of times the new button is pressed. First click opens one window, the second time the new button is clicked two windows open, etc... Any ideas?

问题:需要打开 rad 窗口而不将它们添加到窗口集合或在关闭时将它们从窗口集合中删除。它们不会在 rad 窗口关闭时从窗口集合中删除。这导致按下新按钮的次数相同的窗口打开。第一次点击打开一个窗口,第二次点击新按钮打开两个窗口,等等......有什么想法吗?

C# - Multiple pages opening

C# - 打开多个页面

    RadWindow newWindow = new RadWindow();
    newWindow.NavigateUrl = "WebPage.aspx";
    newWindow.Top = Unit.Pixel(22);
    newWindow.VisibleOnPageLoad = true;
    newWindow.Modal = true;
    newWindow.Left = Unit.Pixel(0);
    newWindow.Height = 530;
    newWindow.Width = 1000;
    winMgr.Windows.Add(newWindow);

JavaScript - Post Back issue? Page opens and immediately disappears.

JavaScript - 回发问题?页面打开并立即消失。

    var oManager = '<%=winMgr.ClientID %>';
    var oManager = window.radopen("WebPage.aspx", null);
    oManager.setSize(1000, 530); //Width, Height
    oManager.center();
    oManager.SetActive();

Thanks for your help!

谢谢你的帮助!

回答by Santhosh Kumar Gudise

As per Alison's solution, rad window is getting displayed on button click; but is disappearing again immediately. I tried using the code below. It is working fine in my case.

根据艾莉森的解决方案,单击按钮时会显示 rad 窗口;但马上又消失了。我尝试使用下面的代码。在我的情况下它工作正常。

<script type="text/javascript">
    function openRadWin()
    {
        radopen("http://www.google.com", "RadWindow1");
    }
</script>
<asp:Button ID="Button1" Text="Show Window" runat="server" OnClientClick="openRadWin();"  />

Hope, it will be useful for someone.

希望,这对某人有用。

回答by NakedBrunch

You need to return false after clicking your button.

单击按钮后,您需要返回 false。

Try setting your button/JavaScript to something similar to the following:

尝试将您的按钮/JavaScript 设置为类似于以下内容:

Button (aspx)

按钮 (aspx)

<asp:Button ID="btnDoSomething" runat="server" Text="Do Something" OnClientClick="return myFunction();" />

JavaScript

JavaScript

function myFunction() {
    var oManager = window.radopen("WebPage.aspx", null);
    oManager.setSize(1000, 530); //Width, Height
    oManager.center();
    oManager.SetActive();
    return false;
}

回答by GeorgiTunev

First - the basics :) Do you want to open the RadWindow on the client (via JavaScript) or on the server?

首先 - 基础知识 :) 您想在客户端(通过 JavaScript)还是在服务器上打开 RadWindow?

Case 1 - on the client:Alison is right - if you want to open the RadWindow on the client (and there is no server-side event hooked to that postback element), you need to cancel the postback. This is done either by using OnClientClick="return myFunction();"and "return false;" at the end of the function itself (like Alison suggested), or:

案例 1 - 在客户端上:Alison 是对的 - 如果您想在客户端上打开 RadWindow(并且没有连接到该回发元素的服务器端事件),您需要取消回发。这是通过使用 OnClientClick="return myFunction();" 完成的 和“ return false;”在函数本身的末尾(就像艾莉森建议的那样),或者:

OnClientClick="myFynction(); return false;"

OnClientClick="myFynction(); return false;"

When the client click is cancelled, there should be no postback.

当客户端点击被取消时,应该没有回发。

Case 2 - on the server:RadWindow is shown from the server by setting VisibleOnPageLoadto true. Note that the RadWindow / RadWindowManager however, keeps their state across postbacks, that includes all server-side properties, including VisibleOnPageLoad. This being said, if you want to show RadWindow only once, you need to also set EnableViewState=false for the RadWindowManagerthat you are using.

情况 2 - 在服务器上:通过将VisibleOnPageLoad设置为true从服务器显示RadWindow。请注意,RadWindow / RadWindowManager 然而,在回发中保持它们的状态,包括所有服务器端属性,包括 VisibleOnPageLoad。话虽如此,如果您只想显示 RadWindow 一次,您还需要为您正在使用的 RadWindowManager设置EnableViewState=false