RadButton and OnClientClick

3 posts, 0 answers
  1. Chris
    Chris avatar
    28 posts
    Member since:
    Jun 2012

    Posted 01 Dec 2011 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Dec 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 06 Dec 2011 Link to this post

    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
Back to Top