aspnet-js-aspxclientbutton-dot-setenabled-x28-value-x29.md
Sets a value specifying whether the button is enabled.
SetEnabled(
value: boolean
): void
| Name | Type | Description |
|---|---|---|
| value | boolean |
true to enable the button; false to disable it.
|
Use the SetEnabled method on the client to dynamically switch a button’s ability to respond to end-user interactions (such as mouse hovering or clicks). The button’s initial client availability state can be defined by using the ASPxButton.ClientEnabled property.
Note, the SetEnabled method result is not sent to the server side when a request is performed. This means that the disabled/enabled state is not synchronized with the server-side object. If you want to synchronize disabled states between client and server sides, for example, you can use the ASPxHiddenField control, containing the disabled state and restore it on the server side.
View Example: How to disable a button after the first click
Note
The SetEnabled method is not in effect if a button is initially disabled on the server by setting the Enabled property to false.
In this example, the ASPxProgressBar control is used to visualize the progress of a file upload initiated within the ASPxUploadControl. The ASPxClientUploadControl.UploadingProgressChanged client event of the ASPxUploadControl is handled, to supply the ASPxProgressBar control with current progress information. Using the ASPxProgressBar as a separate control, allows placing it at any desired position within the page.
function OnBtnUploadClick(s, e){
if(uploadControl.GetText() != ""){
lblCompleteMessage.SetVisible(false);
pbUpload.SetPosition(0);
uploadControl.Upload();
btnUpload.SetEnabled(false);
pnlProgress.SetVisible(true);
}
}
function OnUploadProgressChanged(s, e){
pbUpload.SetPosition(e.progress);
}
function OnFileUploadComplete(s, e){
if(e.isValid){
btnCancel.SetVisible(false);
btnUpload.SetEnabled(true);
pbUpload.SetPosition(100);
lblCompleteMessage.SetVisible(true);
}
else{
btnUpload.SetEnabled(true);
pnlProgress.SetVisible(false);
}
}
function OnBtnCancelClick(s, e){
uploadControl.Cancel();
btnUpload.SetEnabled(true);
pnlProgress.SetVisible(false);
}
function OnUploadControlTextChanged(s, e){
btnUpload.SetEnabled(s.GetText() != "");
}
...
<dxe:ASPxLabel ID="lblFileSizeMessage" runat="server"
Text="The size of a file to upload shouldn't be greater than 5000 Kb."
CssClass="smallMessage" />
...
<dxuc:ASPxUploadControl ID="uc" ClientInstanceName="uploadControl" runat="server">
<ClientSideEvents UploadingProgressChanged="OnUploadProgressChanged"
FileUploadComplete="OnFileUploadComplete"
TextChanged="OnUploadControlTextChanged" />
</dxuc:ASPxUploadControl>
...
<dxe:ASPxButton ID="btnUpload" ClientInstanceName="btnUpload" runat="server" Text="Upload"
AutoPostBack="False">
<ClientSideEvents Click="OnBtnUploadClick" />
</dxe:ASPxButton>
...
<dxe:ASPxProgressBar ID="pbUpload" ClientInstanceName="pbUpload" runat="server" Width="200px"
Height="23px" />
...
<dxe:ASPxButton ID="btnCancel" ClientInstanceName="btnCancel" runat="server" Text="Cancel"
AutoPostBack="False">
<ClientSideEvents Click="OnBtnCancelClick" />
</dxe:ASPxButton>
...
<dxe:ASPxLabel ID="lblCompleteMessage" ClientInstanceName="lblCompleteMessage"
ClientVisible="False" runat="server" Text="Upload completed" />
...
See Also