OnClientClick not fired ...

5 posts, 0 answers
  1. Ahmet HOSO
    Ahmet HOSO avatar
    12 posts
    Member since:
    Aug 2009

    Posted 19 Feb 2011 Link to this post

    Hi,

    At my project i change all buttons with radbutton. And after that onclientclick scripts not fired. Here is a sample.

    <telerik:RadButton runat="server" ID="btn" OnClientClick="alert('test');"
                                       Width="100" ButtonType="LinkButton
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Feb 2011 Link to this post

    Hello Ahmet,

    The properties that are used to specify the RadButton's (or any RadControl's) client-side events, like OnClientCliking, OnClientClicked and etc., expect the name of the JavaScript function to be passed. So, whenever you handle client-side events of the RadControls for ASP.NET AJAX, pass only the name of the function.

    To achieve your scenario, you can subscribe either OnClientCliking or OnClientClicked events and call the function.
    Your RadButton should look like the following:
    <telerik:RadButton runat="server" ID="btn" OnClientClicked="showalert" Width="100"
                ButtonType="LinkButton" Text="Click">
    </telerik:RadButton>
    JavaScript:
    function showalert()
      {
          alert("test");
      }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ahmet HOSO
    Ahmet HOSO avatar
    12 posts
    Member since:
    Aug 2009

    Posted 21 Feb 2011 Link to this post

    Hi Shinu,

    Thanks alot for your response. I have two more questions.

    1 ) How can i pass extra parameter to to java script method. I see an sender and argument parameters exist for button. How can i send custom parameters to argument.

    2 ) If i want to cancel postback how can i do that. Normally if i wrote to the client click like onclientclik='showalert();return false;' it works. But on clientclicked not except this kind of codding. It retiurns javascript exception.

    Regards ..
  5. Ahmet HOSO
    Ahmet HOSO avatar
    12 posts
    Member since:
    Aug 2009

    Posted 21 Feb 2011 Link to this post

    Hi Shinu,

    After some try i find out to send extra parameter and cancel post back.
    I am using  OnClientClinking for cancelling. And with function (sender,e) {..} i can add custom parameter.
    If you can check my code and inform me a better way exist i will be happy.

    <telerik:RadButton ID="btn_Close"
                        runat="server" CausesValidation="false" OnClientClicking="function (sender,e){CloseWindow();e.set_cancel(true);}" />
  6. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Feb 2011 Link to this post

    Hello Ahmet,

    Yes this is one of the approaches to use when you need to pass custom parameter to your button click handler. Another way you could try is, set the CommandArgument property of the button to the parameter you want to pass, and then access it in the handler using sender.get_commandArgument() method.

    There are two ways to control the postback of the RadButton on the client:
    • In the handler of the clicking event (OnClientClicking property) use e.set_cancel(true) - like you have done.
    • Use the button.set_autoPostBack(true/false) method to enable/disable postbacks of the RadButton.

    Kind regards,
    Pero
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017