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

OnClientClick not fired ...

4 Answers 642 Views
Button
This is a migrated thread and some comments may be shown as answers.
Ahmet HOSO
Top achievements
Rank 1
Ahmet HOSO asked on 20 Feb 2011, 01:25 AM
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

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Feb 2011, 06:53 AM
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.
0
Ahmet HOSO
Top achievements
Rank 1
answered on 21 Feb 2011, 10:55 AM
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 ..
0
Ahmet HOSO
Top achievements
Rank 1
answered on 21 Feb 2011, 12:33 PM

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);}" />
0
Pero
Telerik team
answered on 21 Feb 2011, 03:26 PM
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!
Tags
Button
Asked by
Ahmet HOSO
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ahmet HOSO
Top achievements
Rank 1
Pero
Telerik team
Share this question
or