Modify CSS class.

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

I have given up looking for a solution so I figured I would break down
and ask.

I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple

HTMLID.Style["width"] = "10px";

however I need to apply it to a CSS class not a single ID.
What is the code for that?

Thanks
 
Most of the time it will not be a webcontrol.

So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.



If it's a WebControl, change the CssClass property.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.




I have given up looking for a solution so I figured I would break down
and ask.
I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple
HTMLID.Style["width"] = "10px";
however I need to apply it to a CSS class not a single ID.
What is the code for that?
Thanks- Hide quoted text -

- Show quoted text -
 
What is this then ? You can always change the class name.

IMO it will more manageable to change the classname depending on whatever
the condition is rather than to alter the class definition (is this what you
had in mind ?). You could do this frlom ASPX (after all an ASPX page could
perfectly serve CSS content) or using javascript.

Knowing what exactly you are trying to do could perhaps allows someone to
sugest another approach for the problem you try to solve (for example my
first thought would be rather to have a "MyName" and "MyName_Alternate"
class and to use the appropriate name depending on whatever the condition
is.

Will said:
Most of the time it will not be a webcontrol.

So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.



If it's a WebControl, change the CssClass property.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.




I have given up looking for a solution so I figured I would break down
and ask.
I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple
HTMLID.Style["width"] = "10px";
however I need to apply it to a CSS class not a single ID.
What is the code for that?
Thanks- Hide quoted text -

- Show quoted text -
 
Oh BTW I've done something similar for "theming" and ASP application while
keeping the existing layout unchanged (basically it uses a general sheet
that perform the general layout and use one of the multiple sheets that
handle colors).

Bascially you could just inject the appropriate CSS change inside this
particular page. It should "override" just the property you want for this
class.
So your page would use the usual style sheet but would embed a style tag for
this particular css class name so that you can override part of all of its
properties.

The best approach likely depends about what is the purpose of this kind of
"override"...

Patrice said:
What is this then ? You can always change the class name.

IMO it will more manageable to change the classname depending on whatever
the condition is rather than to alter the class definition (is this what
you had in mind ?). You could do this frlom ASPX (after all an ASPX page
could perfectly serve CSS content) or using javascript.

Knowing what exactly you are trying to do could perhaps allows someone to
sugest another approach for the problem you try to solve (for example my
first thought would be rather to have a "MyName" and "MyName_Alternate"
class and to use the appropriate name depending on whatever the condition
is.

Will said:
Most of the time it will not be a webcontrol.

So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.



If it's a WebControl, change the CssClass property.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.





I have given up looking for a solution so I figured I would break down
and ask.

I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple

HTMLID.Style["width"] = "10px";

however I need to apply it to a CSS class not a single ID.
What is the code for that?

Thanks- Hide quoted text -

- Show quoted text -
 
That was the original route I went, making a different class, and alt,
and then swaping thoses around, that was after looking at at themes.
However that because a mess because it is more then 1 CSS class.

I then tried to add mutliple CSS classes but that just ran into
problems on that. So the next idea was just modify the CSS class as
needed, since it is so easy to do with IDs. As it is I now I am more
interested in it from a curiosity standpoint.

What is this then ? You can always change the class name.

IMO it will more manageable to change the classname depending on whatever
the condition is rather than to alter the class definition (is this what you
had in mind ?). You could do this frlom ASPX (after all an ASPX page could
perfectly serve CSS content) or using javascript.

Knowing what exactly you are trying to do could perhaps allows someone to
sugest another approach for the problem you try to solve (for example my
first thought would be rather to have a "MyName" and "MyName_Alternate"
class and to use the appropriate name depending on whatever the condition
is.

"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...


Most of the time it will not be a webcontrol.
So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.
If it's a WebControl, change the CssClass property.
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com
The shortest distance between 2 points is a curve.

I have given up looking for a solution so I figured I would break down
and ask.
I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple
HTMLID.Style["width"] = "10px";
however I need to apply it to a CSS class not a single ID.
What is the code for that?
Thanks- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
Or see my other post (basically you perhaps "inject" those CSS changes
inside your ASPX page to "overrides" previously defined values).

Why do you have so much changes ? Do you alter the appearance based on the
current state of something ?


"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...
That was the original route I went, making a different class, and alt,
and then swaping thoses around, that was after looking at at themes.
However that because a mess because it is more then 1 CSS class.

I then tried to add mutliple CSS classes but that just ran into
problems on that. So the next idea was just modify the CSS class as
needed, since it is so easy to do with IDs. As it is I now I am more
interested in it from a curiosity standpoint.

What is this then ? You can always change the class name.

IMO it will more manageable to change the classname depending on whatever
the condition is rather than to alter the class definition (is this what
you
had in mind ?). You could do this frlom ASPX (after all an ASPX page could
perfectly serve CSS content) or using javascript.

Knowing what exactly you are trying to do could perhaps allows someone to
sugest another approach for the problem you try to solve (for example my
first thought would be rather to have a "MyName" and "MyName_Alternate"
class and to use the appropriate name depending on whatever the condition
is.

"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...


Most of the time it will not be a webcontrol.
So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.
If it's a WebControl, change the CssClass property.
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com
The shortest distance between 2 points is a curve.

I have given up looking for a solution so I figured I would break down
and ask.
I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple
HTMLID.Style["width"] = "10px";
however I need to apply it to a CSS class not a single ID.
What is the code for that?
Thanks- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
Laziness on my part and user requirement.

They want some parts of the design to change to change depending on
role of the user, type of data being shown and if it is real or
teaching server. Most of them are very simple visiblity, color or
font-style type changes.

I don't want to have to handle alot of multiple file and versions so I
handleing most stuff with as few different stylesheet I can and
settings in the config file. Then in thoses cases that changes had
to be done based on data I didn't want to have to change to every
object I figured I could do a quick change to the few classes since
they already had everything but one or two properties that needed to
be changed.

I will probably just go with changing each ID; just a bunch of extra
lines and a chance that I will miss something but easier to change.

Or see my other post (basically you perhaps "inject" those CSS changes
inside your ASPX page to "overrides" previously defined values).

Why do you have so much changes ? Do you alter the appearance based on the
current state of something ?

"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...
That was the original route I went, making a different class, and alt,
and then swaping thoses around, that was after looking at at themes.
However that because a mess because it is more then 1 CSS class.

I then tried to add mutliple CSS classes but that just ran into
problems on that. So the next idea was just modify the CSS class as
needed, since it is so easy to do with IDs. As it is I now I am more
interested in it from a curiosity standpoint.

What is this then ? You can always change the class name.
IMO it will more manageable to change the classname depending on whatever
the condition is rather than to alter the class definition (is this what
you
had in mind ?). You could do this frlom ASPX (after all an ASPX page could
perfectly serve CSS content) or using javascript.
Knowing what exactly you are trying to do could perhaps allows someone to
sugest another approach for the problem you try to solve (for example my
first thought would be rather to have a "MyName" and "MyName_Alternate"
class and to use the appropriate name depending on whatever the condition
is.
"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...
Most of the time it will not be a webcontrol.
So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.
If it's a WebControl, change the CssClass property.
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com
The shortest distance between 2 points is a curve.

I have given up looking for a solution so I figured I would break down
and ask.
I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple
HTMLID.Style["width"] = "10px";
however I need to apply it to a CSS class not a single ID.
What is the code for that?
Thanks- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
 
Rather than using inline styles, why don't you just put a Literal Control on
the page that contains a style sheet? That way you can control all the
styles in the page from one control.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.

Laziness on my part and user requirement.

They want some parts of the design to change to change depending on
role of the user, type of data being shown and if it is real or
teaching server. Most of them are very simple visiblity, color or
font-style type changes.

I don't want to have to handle alot of multiple file and versions so I
handleing most stuff with as few different stylesheet I can and
settings in the config file. Then in thoses cases that changes had
to be done based on data I didn't want to have to change to every
object I figured I could do a quick change to the few classes since
they already had everything but one or two properties that needed to
be changed.

I will probably just go with changing each ID; just a bunch of extra
lines and a chance that I will miss something but easier to change.

Or see my other post (basically you perhaps "inject" those CSS changes
inside your ASPX page to "overrides" previously defined values).

Why do you have so much changes ? Do you alter the appearance based on the
current state of something ?

"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...
That was the original route I went, making a different class, and alt,
and then swaping thoses around, that was after looking at at themes.
However that because a mess because it is more then 1 CSS class.

I then tried to add mutliple CSS classes but that just ran into
problems on that. So the next idea was just modify the CSS class as
needed, since it is so easy to do with IDs. As it is I now I am more
interested in it from a curiosity standpoint.

What is this then ? You can always change the class name.
IMO it will more manageable to change the classname depending on
whatever
the condition is rather than to alter the class definition (is this what
you
had in mind ?). You could do this frlom ASPX (after all an ASPX page
could
perfectly serve CSS content) or using javascript.
Knowing what exactly you are trying to do could perhaps allows someone
to
sugest another approach for the problem you try to solve (for example my
first thought would be rather to have a "MyName" and "MyName_Alternate"
class and to use the appropriate name depending on whatever the
condition
is.
"Will" <[email protected]> a écrit dans le message de (e-mail address removed)...
Most of the time it will not be a webcontrol.
So far the two solutions I have come up with are, hardcode the ID of
each object I need to apply this to or write some asp.net that
modifies some javascript since javascript can easily make a change to
a css class.
If it's a WebControl, change the CssClass property.
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composerhttp://unclechutney.blogspot.com
The shortest distance between 2 points is a curve.

I have given up looking for a solution so I figured I would break
down
and ask.
I am trying to modify a CSS class in page_load. I have no problem
doing it with an ID with the simple
HTMLID.Style["width"] = "10px";
however I need to apply it to a CSS class not a single ID.
What is the code for that?
Thanks- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
 
Back
Top