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

RadButton and OnClientClick

2 Answers 1682 Views
Button
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Dec 2011, 06:17 PM
Hi All,

New to these controls so please forgive my igmnorance - I have come from an Infragistics background.  I wanted to create a simple page with 3 large buttons which when clicked would take you to the appropriate web page.  Easy I thought!
I declare my button as :-

<telerik:RadButton ID="btnTeamData" runat="server" Text="Team Data" Height="70px" Width="250px" Font-Size="18px" Icon-PrimaryIconUrl="~/Images/indycar_48.png"
Icon-PrimaryIconWidth="48" Icon-PrimaryIconHeight="48" AutoPostBack="False" Icon-PrimaryIconTop="10"
OnClientClicked="btnTeamView_OnClientClicked"
ToolTip="combined data recovered from the Teams">
</telerik:RadButton>

...and I have a javascript function at the top of the page
<script type="text/javascript" language="javascript"> 

function btnTeamView_OnClientClicked()
{
alert('Team View');
document.location.href = './teamview.aspx';
}

</script>

...what's odd is that as soon as the page loads I get the alert and the page tries to jump off to the specified new page.  I haven't clicked the button so why is it calling the OnClientClicked event?  How do I get this to work as I would expect?

Thanks

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Dec 2011, 07:11 AM
Hello,

 I have tried to reproduce the issue but no avail. Here is the sample code.

ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadButton.aspx.cs" Inherits="RadButton" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="scriptmngr" runat="server">
        </asp:ScriptManager>
        <telerik:RadButton ID="RadButton1" runat="server" Text="Click " Height="70px" Width="250px"
            Font-Size="18px" Icon-PrimaryIconWidth="48" Icon-PrimaryIconHeight="48" OnClientClicked="OnClientClicked"
            ToolTip="combined data recovered from the Teams" AutoPostBack="false">
        </telerik:RadButton>
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
 function OnClientClicked()
  {
     window.location.href = './Home1.aspx';
  }
</script>

Also take a look into the following documentation
OnClientClicked

Thanks,
Princy.
0
Slav
Telerik team
answered on 06 Dec 2011, 01:04 PM
Hello Chris,

The original code sample seems valid, so I would suggest checking if any of the other RadControls on your page (if there are such), is throwing a JavaScript error and if their setup is correct. Note that the handlers of all RadControls' client events should be specified only by the name of the handler function or by a function object, otherwise their client objects won't be created properly, which will result in an unexpected behavior as the one you have experienced.

If the information presented above does not help you resolve your difficulties please open a regular support ticket and send us a simple, runnable project that isolates your case so that we can inspect it locally and pinpoint the cause.

Regards,
Slav
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
Chris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Slav
Telerik team
Share this question
or