I have toggle switches to mark a day of the week as closed. The event sender is RadToggleSwitchElement and not RadToggleSwitch. I need to get RadToggleSwitch.Name to extract the day of the week from the control's name which is then used down the line.
RadToggleSwitchElement.Name = null
RadToggleSwitchElement.Parent.Name = null
How can I get the name of the RadToggleSwitch in the ValueChanged event handler?
TIA
5 Answers, 1 is accepted
I've used a lambda expression for now. I'm still wondering if there's a way to do it without and inside the handler.
Hello, Memo,
If I understand you correctly you use RadToggleSwitch controls. If the event sender is RadToggleSwitchElement is it possible for you to set the Name property of the RadToggleSwitchElement instead of RadToggleSwitch. Thus, you would be able to access their names in the ValueChanged event:
this.radToggleSwitch1.ToggleSwitchElement.Name = "Toggle1";
this.radToggleSwitch2.ToggleSwitchElement.Name = "Toggle2";
this.radToggleSwitch1.ToggleSwitchElement.ValueChanged += this.ToggleSwitchElement_ValueChanged;
this.radToggleSwitch2.ToggleSwitchElement.ValueChanged += this.ToggleSwitchElement_ValueChanged;
private void ToggleSwitchElement_ValueChanged(object sender, EventArgs e)
{
RadToggleSwitchElement switchElement = sender as RadToggleSwitchElement;
Console.WriteLine(switchElement.Name);
}
Another possible solution that I can suggest is to make use of the Tag property. It is of type object and you can store any useful information in it and use it when it is necessary.
I hope this information helps. Let me know if I can assist you further.
Regards,
Nadya
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/.
Thank you for your reply, Nadya. This does indeed help.
I am unable to set RadToggleSwitch.ToggleSwitchElement.Name in Element hierarchy editor The change doesn't seem to be saved and the field has a blue square next to the field name whereas others don't (see attached).
So I have two additional questions if I may please:
1) Can the element name be set in the hierarchy editor or only set in code as in you example?
2) What are the blue squares found after some field names?
Thank again!
Hello, Memo,
RadToggleSwitch.ToggleSwitchElement.Name should be set programmatically in the code. If you want to use the Element Hierarchy Editor you can set the Tag property as shown below for each RadToggleSwitchElement:
Then, use the ValueChanged event:
private void ToggleSwitchElement_ValueChanged(object sender, EventArgs e)
{
RadToggleSwitchElement switchElement = sender as RadToggleSwitchElement;
Console.WriteLine(switchElement.Tag);
}
The squares next to the fields indicated that the corresponding field has been modified.
I hope this helps.
Regards,
Nadya
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/.