Solved

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

Posted on 2013-12-30
4
326 Views
Last Modified: 2013-12-31
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
Comment
Question by:rascal
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 39746656
have yo looked into reflection


stackoverflow.com/questions/983157/vb-net-iniatialising-a-class-using-system-reflection-and-system-type-to-create-a
0
 
LVL 4

Accepted Solution

by:
ItWorked earned 500 total points
ID: 39747974
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
 
LVL 1

Author Comment

by:rascal
ID: 39748645
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
 
LVL 1

Author Closing Comment

by:rascal
ID: 39748688
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now