This is a migrated thread and some comments may be shown as answers.

RadButton Target property not working in OnClick event

3 Answers 284 Views
Button
This is a migrated thread and some comments may be shown as answers.
SUBBU
Top achievements
Rank 1
SUBBU asked on 24 Apr 2013, 01:15 PM
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.

3 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 25 Apr 2013, 10:48 AM
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.
0
SUBBU
Top achievements
Rank 1
answered on 26 Apr 2013, 02:29 AM
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. 
0
Danail Vasilev
Telerik team
answered on 26 Apr 2013, 03:02 PM
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.
Tags
Button
Asked by
SUBBU
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
SUBBU
Top achievements
Rank 1
Share this question
or