Solved

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

Posted on 2013-12-30
4
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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