RadButton Target property not working in OnClick event

4 posts, 0 answers
  1. SUBBU
    SUBBU avatar
    10 posts
    Member since:
    Apr 2012

    Posted 24 Apr 2013 Link to this post

    Hi,
    We have a RadButton with Target property set to "_blank".  In the OnClick method we have Response.Redirect("www.google.com").

    But the requested url is not opening in new window. Any suggestion is appreciated. Thanks in advance.
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 25 Apr 2013 Link to this post

    Hello,

    The Target property of the RadButton has a meaning in the context of ButtonType="LinkButton", along with the NavigateUrl property. For example:
    <telerik:RadButton ID="RadButton1" runat="server" Text="Click" NavigateUrl="http://www.google.com"
        ButtonType="LinkButton" Target="_blank" />
    When you click on the RadButton the google URL will be opened in a new tab. The Response.Redirect() method, however, is not an embedded method of the RadButton but part of ASP.NET and that is why it redirects the target url to the current tab.

    More information on using link buttons is avilable here and here.


    Kind regards,
    Danail Vasilev
    the Telerik team
    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 their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. SUBBU
    SUBBU avatar
    10 posts
    Member since:
    Apr 2012

    Posted 25 Apr 2013 Link to this post

    Hi Danail,
    Thanks for your response. Is there any other way that I can open a link in a new/active window(this will be decided in the Page_Load) along with OnClick event using any of the telerik components? We cant use asp components because, in case of hyperlink we dont have OnClick property and in case of Link Button we dont have target property. 
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 26 Apr 2013 Link to this post

    Hello,

    I am not sure about your actual scenario, so I can suggest you try one of the following approaches:

    • Either override the properties of the RadButton that are set in the markup with the desired ones on the server, for example on Page_Load:
    ASPX:
    <telerik:RadButton runat="server" ID="RadButton1" ButtonType="LinkButton" Text="Click"
        NavigateUrl="http://www.bing.com" Target="_top">
    </telerik:RadButton>
    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadButton1.NavigateUrl = "http://www.telerik.com";
        RadButton1.Target = "_blank";
    }
    where the highlighted properties override the ones set declaratively.

    • OR register a startup script that opens a new window with the desired URL, when the server-side OnClick event is triggered. For example:
    ASPX:
    <telerik:RadButton runat="server" ID="RadButton1" Text="Click" OnClick="OnClick1">
    </telerik:RadButton>
    C#:
    protected void OnClick1(object sender, EventArgs e)
    {
        string openURL = "<script language='javascript'>function f() { window.open('http://www.telerik.com/','_blank'); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "openURL", openURL);
    }
    More information on executing JavaScript function on the server-side is available in this help article.

    Kind regards,
    Danail Vasilev
    the Telerik team
    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 their blog feed now.
Back to Top