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

Disabling a radbutton not working

1 Answer 199 Views
Button
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Veteran
Mark asked on 06 Apr 2021, 01:36 PM

     So here is the button code

<div class="row mb-3">
        <div class="col-lg-6">
           <div class="form-inline">
                <telerik:RadButton ID="btnRunAudits" runat="server" SingleClick="true" OnClick="btnRunAudits_Click" CssClass="btn btn-info mr-3">
                    <ContentTemplate>
                        <i class="fal fa-long-arrow-right"></i>Execute System Edits
                    </ContentTemplate>
                </telerik:RadButton>     
                <telerik:RadLabel ID="lblExecuteAuditHistory" runat="server" CssClass="time-stamp" Visible="false"></telerik:RadLabel>
           </div>
        </div>
        <div class="col-lg-6 text-right">
            <telerik:RadButton ID="btnExport" runat="server" OnClientClicking="btnExport_onClientClicking" OnClick="btnExport_Click" CssClass="btn btn-info">
                <ContentTemplate>
                    <i class="fal fa-file-export"></i>Export Option(s)
                </ContentTemplate>
            </telerik:RadButton>
            <telerik:RadButton ID="btnRefreshErrors" runat="server" OnClick="btnRefreshErrors_Click" CssClass="btn btn-refresh" SingleClick="true" Width="100">
                <ContentTemplate>
                    <i class="far fa-sync"></i> Refresh
                </ContentTemplate>
            </telerik:RadButton>
        </div>
    </div>

Here is what normally works but does not:

protected void btnRunAudits_Click(object sender, EventArgs e)
        {
            // CLF - the button should be disabled if you can't click.  But just in case!
            if (util.Db.GetUBUserAssign(ubid) == util.appUserId && IsValidEdit(util.Db.GetUBStatusByUBID(ubid).ToString()))
            {
                btnExport.Enabled = false;  <==========
                btnRefreshErrors.Enabled = false; <=========

                //util.Db.RunUBAuditsBC(ubid);
                BuildExceptionGrid();
                if (gItemizedParsing.Items.Count > 0)
                {
                    plcTraining.Visible = true;
                }
                else
                {
                    Session["UBAuditOpen" + ubid.ToString()] = "T";
                    Response.Redirect("~/ubEditor.aspx?SysID=" + ubid.ToString(), false);
                }
                //add entry into audit history table
                util.Db.SaveLastExecuteInfo(ubid, util.appUserId);
                lbItemsRemaining.Text = util.Db.GetPotentialItemsRemaining(ubid);
                DataTable dt = util.Db.GetLastExecuteInfo(ubid);
                if (dt.Rows.Count > 0)
                {                 
                    lblExecuteAuditHistory.Visible = true;
                    lblExecuteAuditHistory.Text = "Last Executed by " + dt.Rows[0]["displayNm"].ToString() + " at " + dt.Rows[0]["dateup"].ToString();
                }

                btnExport.Visible = true;
                btnRefreshErrors.Visible = true;
            }
            else
            {
                btnRunAudits.Enabled = false;
            }            
        }

I have verified it is hitting the code above noted with <========

Basically when they press the btnRunAudits button i want btnExport and btnRefreshErrors disabled until btnRunAudits is done.

HELP :)

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 09 Apr 2021, 11:59 AM

Hi Mark,

The faced behavior is specific for the AJAX framework and cannot be controlled by us. As you can see in the image below, the page is rendered after the whole Postback /click/ logic is executed, so even if the Enabled state of the buttons is changed, it will not be shown visually:

https://i.stack.imgur.com/JFBGj.jpg

What you can do is to disable the buttons in the OnClientClicked handler of btnRunAudits and enable them back in its server-side click handler

        <script>    
            function btnExport_onClientClicking() {

            }
            function onClicked() {
                $find("btnExport").set_enabled(false);
                $find("btnRefreshErrors").set_enabled(false);

            }
        </script>
        <div class="row mb-3">
            <div class="col-lg-6">
                <div class="form-inline">
                    <telerik:RadButton ID="btnRunAudits" runat="server" SingleClick="true" 
                        OnClick="btnRunAudits_Click" OnClientClicked="onClicked" CssClass="btn btn-info mr-3">
                        <ContentTemplate>
                            <i class="fal fa-long-arrow-right"></i>Execute System Edits
                        </ContentTemplate>
                    </telerik:RadButton>
                    <telerik:RadLabel ID="lblExecuteAuditHistory" runat="server" CssClass="time-stamp" Visible="false"></telerik:RadLabel>
                </div>
            </div>
            <div class="col-lg-6 text-right">
                <telerik:RadButton ID="btnExport" runat="server" OnClientClicking="btnExport_onClientClicking" OnClick="btnExport_Click" CssClass="btn btn-info">
                    <ContentTemplate>
                        <i class="fal fa-file-export"></i>Export Option(s)
                    </ContentTemplate>
                </telerik:RadButton>
                <telerik:RadButton ID="btnRefreshErrors" runat="server" OnClick="btnRefreshErrors_Click" CssClass="btn btn-refresh" SingleClick="true" Width="100">
                    <ContentTemplate>
                        <i class="far fa-sync"></i>Refresh
                    </ContentTemplate>
                </telerik:RadButton>
            </div>
        </div>

    protected void btnRunAudits_Click(object sender, EventArgs e)
    {
        //your RunAudits logic here

        btnExport.Enabled = true;
        btnRefreshErrors.Enabled = true;
    }

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Button
Asked by
Mark
Top achievements
Rank 1
Veteran
Answers by
Vessy
Telerik team
Share this question
or