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

Sudden failure of OnClick event due to client side call (in latest version)?

3 Answers 273 Views
Button
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 19 Feb 2014, 09:16 PM
I've just upgraded to the latest Telerik Ajax controls.

In several of my screens, I use an OnClientClicked event to disable the RadButton after one click to prevent multiple posts.

Now it seems to be failing.  The button is disabled but the postback never occurs.  (If I remove the OnClientClicked, the postback works.)

It is my understanding that this approach is now obsolete.  (I am aware of the 'SingleClick' option and I intend to try it.)

However I have another screen that is using the identical approach and it is still working.  So far I have not been able to find any significant difference.  I'd like to know what's happening here.

3 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 24 Feb 2014, 02:21 PM
Hello Boris,

It seems that the JavaScript code that disables the button cannot be executed due to the postback. Therefore I can suggest that you set some time out to the disabling of the button. For example:
JavaScript:
<script>
    function OnClientClicked(sender, args) {
        setTimeout(function () {
            sender.set_enabled(false);
        }, 50);
    }
</script>
ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="click" OnClientClicked="OnClientClicked" OnClick="RadButton1_Click" />
<asp:Label ID="Label1" Text="" runat="server" />
C#:
protected void Page_Load(object sender, EventArgs e)
{
 
}
protected void RadButton1_Click(object sender, EventArgs e)
{
    Label1.Text = "btn is clicked";
    System.Threading.Thread.Sleep(5000);
}

I have tested the above approach and it seems to be working properly.

Regards,
Danail Vasilev
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Boris
Top achievements
Rank 1
answered on 24 Feb 2014, 02:30 PM
I'm sorry.  I do not understand your answer.  More specifically I do not see the relevance of your answer.

The original problem was that Postback was NOT occurring.  Also the last thing I would want to do in this scenario is delay the disabling of the button. It's important for the button to be disabled as soon as possible after a single click.  This is an extremely common scenario.

In any case, in this one screen, I replaced the Javascript disable with the SingleClick option and so far everything seems to be working normally in this screen.  (In other screens the Javascript disable function is working normally.)
0
Danail Vasilev
Telerik team
answered on 27 Feb 2014, 12:41 PM
Hello Boris,

The ASP Button can be configured as a SingleClick button only when its UseSubmitBehavior property is set to false. For example:
ASPX:
<asp:Button ID="Button1" Text="text" runat="server" OnClientClick="this.disabled = true; this.value = 'Saving...';" OnClick="RadButton1_Click" UseSubmitBehavior="false" />
<asp:Label ID="Label1" Text="" runat="server" />
C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    Label1.Text = "btn is clicked";
    System.Threading.Thread.Sleep(2000);
}

I have tried setting this property to the RadButton too and the button's disabling state and server-side OnClick events seem to work properly on my side. For example:
ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="click" OnClientClicked="function(sender, args){sender.set_enabled(false);}" OnClick="RadButton1_Click" UseSubmitBehavior="false" />
C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    Label1.Text = "btn is clicked";
    System.Threading.Thread.Sleep(2000);
}

You can also find the full runnable VS example in the attached archive.


Regards,
Danail Vasilev
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Button
Asked by
Boris
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Boris
Top achievements
Rank 1
Share this question
or