Opening a New Custom Browser Window Using ButtonType = LinkButton

4 posts, 0 answers
  1. Jon Shipman
    Jon Shipman avatar
    43 posts
    Member since:
    Nov 2009

    Posted 10 Dec 2010 Link to this post

    Requirements

    RadControls version: v.2010.3.1109.35

    .NET version: Any

    Visual Studio version: Any

    programming language: Any

    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    The new RadButton is really cool and highly configurable.  One of the ButtonTypes available is the LinkButton.  I'm using several of the new buttons on a site and I need one to open a link in a new browser window with a custom size.  Note that if you don't care about the size of the new window, you can just set the Target = "_blank".  This project shows how to open a new browser window with custom features.

    1. Set the ButtonType to LinkButton.
    2. Set the NavigateUrl to the desired URL.
    3. Set the OnClientClicking property to the name of your JavaScript function. No parameters or references need to be passed inside parentheses.  Telerik already took care of that for you.  Note that you can't use the "OnClientClicked" property because it is not cancellable.
    The .aspx Markup:
    <telerik:RadButton ID="btnNewWindow"
        runat="server"
        Text="Open in New Window"
        ButtonType="LinkButton"
        NavigateUrl="http://www.telerik.com"
        OnClientClicking="OnClientClicking" />

    1. Pass the desired URL and your custom requirements to the window.open function. The NavigateUrl value is available as "sender._navigateUrl".  
    2. Cancel the click event.  If you don't cancel the event the main window will navigate to the new URL too.  "return false" works with IE, but args.set_cancel(true) works with all supported browsers.
    The JavaScript:
    function OnClientClicking(sender, args)
    {
        window.open(sender._navigateUrl,
                    '_blank',
                    'height=500,width=500,location=no,' +
                    'menubar=yes,resizable=yes,scrollbars=yes,' +
                    'status=no,toolbar=no');
        args.set_cancel(true);
    }

    Pretty simple.  But it took me a while to figure out all the details, so hopefully this will help speed someone else's development!
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 14 Dec 2010 Link to this post

    Hi Jon,

    Thank you for your contribution! I have added 2000 Telerik points to your account.

    By the way, the same scenario can be also achieved using the AutoPostBack property of the RadButton control. Setting this property to false will make the control a client button, and the developer can execute his/her javascript logic in the event handler of clicking (OnClientClicking property) or clicked (OnClientClicked property) client-side event.

    All the best,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. Jon Shipman
    Jon Shipman avatar
    43 posts
    Member since:
    Nov 2009

    Posted 14 Dec 2010 Link to this post

    Thanks!

    I tried your suggestion and it works great with ButtonType="StandardButton", and AutoPostBack="false" and I didn't even have to cancel the args in the function. Good to know!

    I liked the look of the ButtonType="LinkButton" in my case and you still need to cancel the args in Chrome, Firefox, etc. even with AutoPostBack set to false.  I attached a screenshot of the proposed usage.  The "Charts" button is the one that opens a new custom-sized window.  Thanks again!

  4. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 15 Dec 2010 Link to this post

    Hi Jon,

    Yes indeed you still need to cancel the event when ButtonType="LinkButton" is used, because the URL set to the NavigateUrl property will still be opened in the current browser window. Please excuse me for omitting this, and thank you for making it clear.

    Best wishes,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top