Performing various DOM manipulations by accessing ASP.NET controls via their ClientID properties in JavaScript is a common approach in ASP.NET Web Forms for interacting with controls dynamically. Here is a list of possible DOM manipulations you can perform using the ClientID of ASP.NET controls.
1. Disable a Control (e.g., Button, TextBox, DropDownList)
You can disable a control (e.g., a Button, TextBox, DropDownList) by setting its disabled property to true.
document.getElementById('<%= cutoff3.ClientID %>').disabled = true;
Effect: The control becomes non-interactive, preventing user interaction.
2. Enable a Control (e.g., Button, TextBox, DropDownList)
You can enable a control by setting its disabled property to false.
document.getElementById('<%= cutoff3.ClientID %>').disabled = false;
Effect: The control becomes interactive again.
3. Check or Uncheck a Checkbox
To check or uncheck a checkbox, you can manipulate the checked property of a CheckBox control.
document.getElementById('<%= cutoff1.ClientID %>').checked = false; // Uncheck
document.getElementById('<%= cutoff1.ClientID %>').checked = true; // Check
Effect: It changes the state of the checkbox.
4. Set or Get the Value of a TextBox, DropDownList, or RadioButton
You can retrieve or set the value of input controls like TextBox, DropDownList, or RadioButton using the value property.
var textBoxValue = document.getElementById('<%= txtupiid.ClientID %>').value; // Get value
document.getElementById('<%= txtupiid.ClientID %>').value = "New Value"; // Set value
Effect: Allows retrieving or updating the value entered in the input controls.
5. Make a Control Read-Only (e.g., TextBox)
You can make a text field read-only by setting the readOnly property to true or false.
document.getElementById('<%= price1.ClientID %>').readOnly = true; // Set read-only
document.getElementById('<%= price1.ClientID %>').readOnly = false; // Enable editing
Effect: Prevents the user from editing the control if set to
true.
6. Show or Hide an Element (CSS Display Property)
You can dynamically show or hide an element by changing its style.display property.
document.getElementById('<%= lbldiscount1.ClientID %>').style.display = 'block'; // Show
document.getElementById('<%= lbldiscount1.ClientID %>').style.display = 'none'; // Hide
Effect: Controls the visibility of the element.
7. Change the Inner Text of an Element (e.g., Label, Div)
You can change the displayed text of an element (like a Label or Div) by modifying its innerText or innerHTML property.
document.getElementById('<%= clupi.ClientID %>').innerText = "New Text"; // Set text
Effect: Modifies the content of the element dynamically.
8. Change the Inner HTML of an Element
For more complex HTML content inside an element, you can use innerHTML.
document.getElementById('<%= total.ClientID %>').innerHTML = "<b>Updated Content</b>"; // Set HTML
Effect: Modifies the entire HTML inside the control.
9. Manipulate a Control's CSS Style (e.g., Font Size, Color, Background)
You can dynamically change the CSS styles of any control using style properties.

Join the conversation! Your thoughts help the community grow.