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

4 posts, 0 answers
  1. Boris
    Boris avatar
    275 posts
    Member since:
    Oct 2012

    Posted 19 Feb 2014 Link to this post

    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.

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 24 Feb 2014 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boris
    Boris avatar
    275 posts
    Member since:
    Oct 2012

    Posted 24 Feb 2014 in reply to Danail Vasilev Link to this post

    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.)
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 27 Feb 2014 Link to this post

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