Solved

asp.net button styles

Posted on 2004-03-25
7
1,431 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
  • 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
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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: blockā€¦
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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