PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 2.33 average.

How can I change an element's class in the code behind?

 
 
moondaddy
Guest
Posts: n/a
 
      30th Mar 2004
I have some table cells with the runat attribute set to server. In the
codebehind I can see these cells but I don't see any properties to change
their class. How can this be done from the code behind?

--
(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Cliff Harris
Guest
Posts: n/a
 
      30th Mar 2004
It looks like when you use it as a server-side control, it wants you to use
the .Style member to adjust style settings. However, if you want to "cheat"
to get it to work, just use the "Attributes" property of the control:

tablecell1.Attributes.Add("class", "MyCssClass");

That's the only way I could find to do it.

HTH,
-Cliff

"moondaddy" <(E-Mail Removed)> wrote in message
news:%23YM$(E-Mail Removed)...
> I have some table cells with the runat attribute set to server. In the
> codebehind I can see these cells but I don't see any properties to change
> their class. How can this be done from the code behind?
>
> --
> (E-Mail Removed)
>
>



 
Reply With Quote
 
 
 
 
moondaddy
Guest
Posts: n/a
 
      30th Mar 2004
I found a way. Please let me know if there's a better way than this.

Thanks.

'First remove the class attribute from the cell
Me.cellStatusBar1.Attributes.CssStyle.Remove("class")
'Now add it back in specifying which class to use
Me.cellStatusBar1.Attributes.Add("class", "clsChkOutBar_NormalText")


--
(E-Mail Removed)
"moondaddy" <(E-Mail Removed)> wrote in message
news:%23YM$(E-Mail Removed)...
> I have some table cells with the runat attribute set to server. In the
> codebehind I can see these cells but I don't see any properties to change
> their class. How can this be done from the code behind?
>
> --
> (E-Mail Removed)
>
>



 
Reply With Quote
 
Cliff Harris
Guest
Posts: n/a
 
      30th Mar 2004
The first of your two statement has an error...
Me.cellStatusBar1.Attributes.CssStyle.Remove("class")
will remove a style attribute.. for example.. if my tag in HTML looks like
this

....
<td id="cell1" style="color:red" runat="server">
....

and I have this in my codebehind
cell1.Attributes.CssStyle.Remove("color");

the following tag would be produced on the client:
....
<td id="cell1" style="" runat="server">
....

The reason it still works for you is because, as I tested, if you add an
attributes (in your case the "class" attribute) and it already exists, it is
overridden. If you want to still remove it, you would just modify it like
this:

'First remove the class attribute from the cell
Me.cellStatusBar1.Attributes.Remove("class")
'Now add it back in specifying which class to use
Me.cellStatusBar1.Attributes.Add("class", "clsChkOutBar_NormalText")

-Cliff

PS Sorry about the mix of C# and VB... I'm sure you still get it...


"moondaddy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I found a way. Please let me know if there's a better way than this.
>
> Thanks.
>
> 'First remove the class attribute from the cell
> Me.cellStatusBar1.Attributes.CssStyle.Remove("class")
> 'Now add it back in specifying which class to use
> Me.cellStatusBar1.Attributes.Add("class", "clsChkOutBar_NormalText")
>
>
> --
> (E-Mail Removed)
> "moondaddy" <(E-Mail Removed)> wrote in message
> news:%23YM$(E-Mail Removed)...
> > I have some table cells with the runat attribute set to server. In the
> > codebehind I can see these cells but I don't see any properties to

change
> > their class. How can this be done from the code behind?
> >
> > --
> > (E-Mail Removed)
> >
> >

>
>



 
Reply With Quote
 
moondaddy
Guest
Posts: n/a
 
      2nd Apr 2004
Thanks that helps to clear it up. In short what I wanted to do was to
change from one style class to another. I thought that if I didn't remove
it first I would get a conflict or have it in there 2 times, but since it
gets overridden, then removing it is unnecessary.

--
(E-Mail Removed)
"Cliff Harris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The first of your two statement has an error...
> Me.cellStatusBar1.Attributes.CssStyle.Remove("class")
> will remove a style attribute.. for example.. if my tag in HTML looks like
> this
>
> ...
> <td id="cell1" style="color:red" runat="server">
> ...
>
> and I have this in my codebehind
> cell1.Attributes.CssStyle.Remove("color");
>
> the following tag would be produced on the client:
> ...
> <td id="cell1" style="" runat="server">
> ...
>
> The reason it still works for you is because, as I tested, if you add an
> attributes (in your case the "class" attribute) and it already exists, it

is
> overridden. If you want to still remove it, you would just modify it like
> this:
>
> 'First remove the class attribute from the cell
> Me.cellStatusBar1.Attributes.Remove("class")
> 'Now add it back in specifying which class to use
> Me.cellStatusBar1.Attributes.Add("class", "clsChkOutBar_NormalText")
>
> -Cliff
>
> PS Sorry about the mix of C# and VB... I'm sure you still get it...
>
>
> "moondaddy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I found a way. Please let me know if there's a better way than this.
> >
> > Thanks.
> >
> > 'First remove the class attribute from the cell
> > Me.cellStatusBar1.Attributes.CssStyle.Remove("class")
> > 'Now add it back in specifying which class to use
> > Me.cellStatusBar1.Attributes.Add("class", "clsChkOutBar_NormalText")
> >
> >
> > --
> > (E-Mail Removed)
> > "moondaddy" <(E-Mail Removed)> wrote in message
> > news:%23YM$(E-Mail Removed)...
> > > I have some table cells with the runat attribute set to server. In

the
> > > codebehind I can see these cells but I don't see any properties to

> change
> > > their class. How can this be done from the code behind?
> > >
> > > --
> > > (E-Mail Removed)
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't specify a location for new class code file on class diagram>new class dialog? Andy B Microsoft C# .NET 3 14th Feb 2008 02:57 AM
Can I make a Common Array Class and create a instance of the Common Array Class with Type of a new class Peri Microsoft C# .NET 10 17th Oct 2007 07:37 AM
Can I make a Common Array Class and create a instance of the Common Array Class with Type of a new class Peri Microsoft VB .NET 10 17th Oct 2007 07:37 AM
call a mnuFileNew_Click method from a Main MDI class from another class (can be a MdiChild class.. )? M. G, Microsoft Dot NET Framework Forms 1 31st May 2006 06:28 AM
Can it possible redefine class with subclass when inherit base class with sub class? ABC Microsoft C# .NET 4 11th Jan 2006 12:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:55 AM.