• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

How to dynamically set a VB.NET control's class?

I am trying to dynamically set a class (not the style attribute, the class) on a VB.NET control whenever the user selects an item from a dropdown. The dropdown has a list of class names in it, and I want to show the user what the effect of that class is by setting another control's class to that selected class. I am unable to set the CssClass of the target control because that attribute is read-only.

Is there a way to dynamically set a control's CLASS by responding to a dropdown list change?

thanks experts!
0
rascal
Asked:
rascal
  • 2
1 Solution
 
Ess KayEntrapenuerCommented:
have yo looked into reflection


stackoverflow.com/questions/983157/vb-net-iniatialising-a-class-using-system-reflection-and-system-type-to-create-a
0
 
Hiran DesaiSolution ArchitectCommented:
I don't know where you find that CssClass is readonly...as

With your question i have cross checked my knowledge with MSDN at Webcontrol.CssClass

If still in case doesn't work then you can do it by
control.Attributes.add("class","classname");

Open in new window


Let me know if this doesn't works
0
 
rascalAuthor Commented:
Thanks ItWorked,
When I attempted to set the CssClass property, the tooltip presented by Visual Studio displayed that it was read only, and Visual Studio underlined the statement, but I'll give it a try and also try the control.Attributes.add("class","classname") approach and let you know.
0
 
rascalAuthor Commented:
Thanks ItWorked, the control.Attributes.add("class","classname") worked.

I also tried the CssClass version but that still didn't work. Below is the element I was trying to dynamically add the CssClass to:

<aside id="ctlSampleText" class="<%=sSelectedScheme%>" runat="server" ClientIDMode="Static">
          This is sample text. <a href="javascript:void(0)">This is a sample link</a>
      </aside>
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now