Solved

asp.net button styles

Posted on 2004-03-25
7
1,434 Views
Last Modified: 2010-08-05
I am doing a project in asp.net.  The site has a dozen asp web control buttons on it.  The client wants a certain style applied to all buttons.  What do I put in the style sheet?
0
Comment
Question by:dbyrne03
[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
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10676923
the style sheet.

.buttclss {color:blue; other properties etc}

The in you code where you generate the buttons add a class attribute:

class="buttclss"

Cd&
0
 

Author Comment

by:dbyrne03
ID: 10679367
I was hoping to avoid this because although it allows me to centrally manage the behavior and appearance of buttons from one file, the style sheet, I still have to go around to every button in the site and type " class='buttclss'" .  For example, if you want to apply a style to all <td> elements, you don't need to put class='tdclss' in every <td> element in your site, you just put
td { color:blue }
in the style sheet.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10682028
Not necessarily.  you could do it dynamically with script:

<script type="text/javascript">
<!--
function setstyle()
{
   for (i=0;i<document.forms.length;i++)
   {
      frm=document.forms[i]
      for (j=0;j<frm.elements.length;j++)
       {
           target=frm.elements[j];
           if (target.type=="BUTTON" || target.type=="SUBMIT" || target.type=="RESET")
target.className="buttclss";
        }
     }
 }
onload.=setstyle;
//-->
</script>

Just put that in a .js file and source it in in the head of the pages.

Cd&
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dbyrne03
ID: 10682463
couple of quick things.  first, thanks for the script.  there was an error for
onload.=setstyle;
so I changed it to
onload=setstyle;

But it still didn't work.  So I put
alert(target.type);
right before
target.className="buttclss";

the weird thing is, the alert box does not pop up, but the style does take effect.  what is even more weird, the style is applied to textboxes as well.  check out http://137.229.174.53:8080/search.aspx
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 100 total points
ID: 10683034
My bad.  I didn't deal with the case.  The if needs to look like this.

if (target.type.toLowerCase()=="button" || target.type.toLowerCase()=="submit" || target.type.toLowerCase()=="reset")
{
target.className="buttclss";
}

What happened when you put the alert in is it change the scope of the if.  An if without {} has a scope of just the next command.  So setting the class became unconditional.

Cd&
0
 

Author Comment

by:dbyrne03
ID: 10683503
that was it.  thanks buddy.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10695029
Glad I could help.  Thanks for the A/ :^)

Cd&
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to delete "dots" above Bootstrap 3 navbar 4 128
BG appearing and then disappaear after a second 8 62
CSS auto-height of empty div 3 73
iframe stay to the left of page 5 30
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

710 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