I've got an ASP.NET control say checkbox:
<asp:CheckBox ID="myChck" runat="server" Value="myCustomValue" />
Is it possible to add this custom Value
attribute from code-behind and respectively get the value from Value
Something like (psuedocode):
myCkck.Value = "blq blq";
string chckValue = myChck.Value;
How can I do this?
AttributeUsage has a named parameter, AllowMultiple , with which you can make a custom attribute single-use or multiuse. In the following code example, a multiuse attribute is created. In the following code example, multiple attributes of the same type are applied to a class.
Attributes are used to impose conditions or to increase the efficiency of a piece of code. There are built-in attributes present in C# but programmers may create their own attributes, such attributes are called Custom attributes. To create custom attributes we must construct classes that derive from the System.
A custom attribute is a property that you can define to describe assets. Custom attributes extend the meaning of an asset beyond what you can define with the standard attributes. You can create a custom attribute and assign to it a value that is an integer, a range of integers, or a string.
It's perfectly possible:
myCkck.Attributes.Add("Value", "blq blq");
string chckValue = myChck.Attributes["Value"].ToString();
You could create a new class that inherits the CheckBox class (or any other control class for that matter) and add any further properties you need to the derived class. That way you would get an extended CheckBox more or less.
public class ExtendedCheckBox : CheckBox
{
public string Value
{
get;
set;
}
public ExtendedCheckBox : base()
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With