How to Enable a button true or false on button click

3 posts, 1 answers
  1. salvio
    salvio avatar
    17 posts
    Member since:
    Oct 2010

    Posted 19 Mar 2011 Link to this post

    Hai Telerik Team,

    How I have to restrict user to click button repeatedly....
    If the user click on the  button  first, it should enabled= false and showing button text like "Submitting"
    after submitted, the button changed to enabled=true...So how to do this in "RADAJAXMANAGER"
    or write some other solution to solve this pls...

    Ex Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="Default4" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="rad" %>
     
    <head runat="server">
        <title></title>
      
     
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         
        <asp:ToolkitScriptManager ID="tool123"  runat ="server" ScriptMode ="Release" >
       </asp:ToolkitScriptManager>
             
            <rad:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
             <rad:AjaxSetting AjaxControlID="btn_sb">
                    <UpdatedControls>
                   <rad:AjaxUpdatedControl ControlID="lab_nm" LoadingPanelID ="RadAjaxLoadingPanel1" />
                </UpdatedControls>
                </rad:AjaxSetting>
                 
                </AjaxSettings>
            
     
        </rad:RadAjaxManager>
         
        <rad:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="" Transparency="30">
                      <asp:Image ID="Image1" runat="server" ImageUrl="~/IMAGES/AjaxLoadingImg/LoadingProgressBar.gif"
                AlternateText="loading" />
        </rad:RadAjaxLoadingPanel>
         
             
            <asp:Button ID="btn_sb" runat="server" Text="Telerik" /><br />
            <asp:Label ID="lab_nm" runat="server"
               ></asp:Label>
            
        </div>
        </form>
    </body>
    </html>
    ---------------------------------------------------------------------------------------------------------------
     
     Protected Sub btn_sb_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_sb.Click
            lab_nm.Text = "You Clicked Telerik Button"
        End Sub

    I need---On click btn_sb it should enable false and showing some text like "submitting" after page submitted it returns to enabled true..




  2. Answer
    Vasil
    Admin
    Vasil avatar
    1642 posts

    Posted 21 Mar 2011 Link to this post

    Hello salvio,

    You can disable the button on it's client click event. And enable it after the ajax request is completed. Check the code snippet bellow:

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadCodeBlock runat="server">
      <script type="text/javascript">
        var button = null;
        function btn_ClientClick(sender, args) {
          button = sender;
          button.disabled = true;
        }
      </script>
    </telerik:RadCodeBlock>
    <script runat="server" type="C#">
      protected void btn_sb_Click(object sender, EventArgs e)
      {
        RadAjaxManager1.ResponseScripts.Add("button.disabled=false;");
      }
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
      <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="btn_sb">
          <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="lab_nm" LoadingPanelID="RadAjaxLoadingPanel1" />
          </UpdatedControls>
        </telerik:AjaxSetting>
      </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="" Transparency="30">
      <asp:Image ID="Image1" runat="server" ImageUrl="~/IMAGES/AjaxLoadingImg/LoadingProgressBar.gif"
        AlternateText="loading" />
    </telerik:RadAjaxLoadingPanel>
    <asp:Button ID="btn_sb" runat="server" Text="Telerik" OnClick="btn_sb_Click" OnClientClick="btn_ClientClick(this)" />
    <br />
    <asp:Label ID="lab_nm" runat="server"></asp:Label>

    Greetings,
    Vasil
    the Telerik team
  3. salvio
    salvio avatar
    17 posts
    Member since:
    Oct 2010

    Posted 21 Mar 2011 Link to this post

    Thank you Vasil for your code.
Back to Top