简体   繁体   English

启用/禁用按钮

[英]Enable/Disable a button

I have a button as follows: 我有一个按钮,如下所示:

RadButton lnkAdd = new RadButton();
lnkAdd.ID = "BtnAdd";
lnkAdd.CommandName = RadGrid.InitInsertCommandName;
lnkAdd.Text = "Add New Record";
lnkAdd.Style.Add("display", "none");
container.Controls.Add(lnkAdd);

I want to enable it on click of a row in the grid. 我想在网格中单击一行时启用它。 I have the following JavaScript to do this: 我有以下JavaScript可以做到这一点:

function OnRowSelected(sender, args) {       
    var clientDataKeyName = args.get_tableView().get_clientDataKeyNames()[0];   
    var clientDataKeyValue = args.get_tableView().get_selectedItems()[0].getDataKeyValue(clientDataKeyName);     
    var grid = args.get_tableView(); 
    var linkButton1 = $telerik.findControl(grid.get_element(), "BtnAdd");  
    if (clientDataKeyValue == "Proposal") {
        linkButton1.set_enabled(false);
    }
    else
        linkButton1.set_enabled(true);
}

Though it reaches the linkButton1.set_enabled(true) , the button is not enabled. 尽管到达linkButton1.set_enabled(true) ,但该按钮未启用。 I also tried the following to enable the button linkButton1.style.display = "block"; 我还尝试了以下操作来启用按钮linkButton1.style.display = "block"; But this throws an error: 但这会引发错误:

SCRIPT5007: Unable to set property 'display' of undefined or null reference. SCRIPT5007:无法设置未定义或空引用的属性“显示”。

Though it finds the button, style is rendered as undefined. 尽管找到了按钮,但样式仍呈现为未定义。

由于仅通过按钮的显示CSS属性隐藏了按钮的主要包装元素,因此应使用相同的内容再次显示该按钮:

linkButton1.get_element().style.display="inline-block";

Any UIControl (including RadioButtons) can be enabled and disabled using the IsEnabled property. 可以使用IsEnabled属性启用和禁用任何UIControl(包括RadioButtons)。 Basically, you can just set the button to 基本上,您可以将按钮设置为

linkButton1.IsEnabled = false;

In order to disable the button and 为了禁用按钮和

linkButton1.IsEnabled = true;

to reenable it. 重新启用它。 Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM