Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do you programmatically apply a css class to an string variables?
for example,
string something="
" //it can be working
string something="
" //it cannot working for applying css class name...
why?..........
Posted
Updated 14-Nov-11 2:37am
v2
Comments
thatraja 14-Nov-11 8:15am    
Rephrase your question.
balavino 14-Nov-11 8:27am    
how to add cssclass in string variables in C#
Sergey Alexandrovich Kryukov 14-Nov-11 13:49pm    
My vote of 1 for writing gibberish. A person can only get some help if she or he understand what should be achieved.
--SA

If you want to apply CSS for controls using Code-behind then try this
ASP.NET
<asp:panel id="Panel1" runat="server" xmlns:asp="#unknown">
Hello World
</asp:panel>

C#
Panel1.CssClass = "PanelStyle";

or
C#
Panel1.Attributes.Add("class", "PanelStyle");
 
Share this answer
 
Comments
balavino 14-Nov-11 8:29am    
am not using any controls..
thatraja 14-Nov-11 8:31am    
Your question makes no sense, Can you explain more about that?
balavino 14-Nov-11 8:41am    
for eg,
string something="<table style="color:Red;"></table>";//it can be working..in codebehind C#

string something="<table class="somename"></table>";//it cannot working
why?....
is it possible....
thatraja 14-Nov-11 8:44am    
Did you create the CSS class in that page?
balavino 14-Nov-11 8:49am    
no...
You cannot do so.

CSS is for styling controls (not variables).
Styling a variable makes no sense.
 
Share this answer
 
Comments
balavino 14-Nov-11 8:41am    
for eg, string something="<table style="color:Red;"></table>";//it can be working..in codebehind C# string something="<table class="somename"></table>";//it cannot working why?.... is it possible....
Yvan Rodrigues 14-Nov-11 8:55am    
To apply CSS a variable in Codebehind requires that you use controls (Web forms).
balavino 14-Nov-11 8:59am    
string is used to send mail purpose
Sergey Alexandrovich Kryukov 14-Nov-11 13:47pm    
So what? This is not related to styles.
--SA
balavino 14-Nov-11 9:00am    
if using webforms its working....
put this string in some control DIV,Label and set css on runtime.:)
 
Share this answer
 
Comments
balavino 14-Nov-11 8:41am    
for eg, string something="<table style="color:Red;"></table>";//it can be working..in codebehind C# string something="<table class="somename"></table>";//it cannot working why?.... is it possible....
Sergey Alexandrovich Kryukov 14-Nov-11 13:51pm    
OP is beyond repair. :-<
However, I'll vote 5 for this solution which could give a right idea -- but only to a right person :-),
voting 3 for this answer was ridiculous.
--SA
Anuj Banka 15-Nov-11 1:35am    
Use <DIV id="Test" runat="server">Your Content <Div> Table you can't access On server side.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900