open radwindow in C# with js code.

6 posts, 2 answers
  1. Ben
    Ben avatar
    31 posts
    Member since:
    Feb 2013

    Posted 02 Aug 2013 Link to this post

    Hi

    I am trying to open a radwindow from C# on click of a button. I tried several codes available in the internet to invoke the js defined in the aspx page to open the radwindow but every time I get a js function undefined error. Please someone help me with a full solution.

    Thanks in advance.
    Ben
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Aug 2013 Link to this post

    Hi Ben,

    Please have a look into the following full code I tried to open a RadWindow from C# code using JavaScript defined in the ASPX.

    ASPX:
    <telerik:RadWindow ID="RadWindow1" runat="server" Width="450px" Height="450px" NavigateUrl="http://www.telerik.com">
    </telerik:RadWindow>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Open From Server" OnClick="RadButton1_Click">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function openRadWindow() {
            var radwindow = $find('<%=RadWindow1.ClientID %>');
            radwindow.show();
        }
    </script>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        string script = "function f(){openRadWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 02 Aug 2013 Link to this post

    Hi,

    You can see the following sticky note on the subject: Opening RadWindow from the server and try the solutions provided in it.

    This help article could be helpful too: Using RadConfirm In Server Code.

    Best regards,
    Rumen
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  5. Ben
    Ben avatar
    31 posts
    Member since:
    Feb 2013

    Posted 02 Aug 2013 Link to this post

    Thanks a lot lot Shinu. Hi Rumen, those links didn't help me since my primary aim was to invoke the js in aspx from C# code.
  6. Ben
    Ben avatar
    31 posts
    Member since:
    Feb 2013

    Posted 03 Sep 2013 Link to this post

    Hi shinu. I have another query. How can I set the radwindow size as 90%  of parent window even on browser resizing?
  7. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2013 Link to this post

    Hi Ben,

    Please check the following code.

    ASPX:
    <telerik:RadButton ID="RadButton1" runat="server" Text="Open RadWindow" OnClientClicked="openRadWindow"
        AutoPostBack="false">
    </telerik:RadButton>
    <telerik:RadWindow ID="RadWindow1" runat="server" NavigateUrl="http://www.telerik.com">
    </telerik:RadWindow>

    JavaScript:
    <script type="text/javascript">
        var $ = $telerik.$;
        var radwindow;
     
        function pageLoad() {
            radwindow = $find("<%= RadWindow1.ClientID%>");
        }
     
        function openRadWindow() {
            radwindow.show();
            setWindowsize();
        }
     
        $(window).resize(function () {
            if (radwindow.isVisible()) {
                setWindowsize();
            }
        });
     
        function setWindowsize() {
            var viewportWidth = $(window).width();
            var viewportHeight = $(window).height();
            radwindow.setSize(Math.ceil(viewportWidth * 90 / 100), Math.ceil(viewportHeight * 90 / 100));
            radwindow.center();
        }
    </script>

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017