views:

78

answers:

3

I have this code, and it renders this HTML. How can I apply CSS to my control if they are named ctrctrctr-00000 or something else like that that is only useful to the VIEWSTATE?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head><title>

</title><link href="../global.css" rel="stylesheet" type="text/css" />
Informacion General: Paises
</head>
<body>
    <form name="aspnetForm" method="post" action="Pais.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUyMDk1NTY2MGRkwAKu2OIV85kXfcUcAefBBNmSuRY=" />
</div>

<div>

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLSha7NBAKqw7ARAvjQlaIKhJ2HMftmmOoxe/+aE4sG3D32QtA=" />
</div>
    <div>

    <input name="ctl00$ContentPlaceHolder1$txtPais" type="text" id="ctl00_ContentPlaceHolder1_txtPais" />
    <input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Button" id="ctl00_ContentPlaceHolder1_btnSubmit" />

    </div>
    </form>
</body>
</html>



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Frontend._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>    
        <h1>Prueba de Escritorio</h1>        
        <asp:TextBox ID="txtPais" runat="server"></asp:TextBox>
        <asp:Button ID="btnSubmit" runat="server" Text="Guardar" onclick="btnSubmit_Click" />    
    </div>
    </form>
</body>
</html>

How can I use a CSS selector to target ALL textboxes on the page regardless of name?

Thank you.

A: 

you can use jQuery and do it like this:

$('input[id$=_txt]').addClass('yourClassName maybeAnotherClassName');
TheGeekYouNeed
What does $('input[id$=_txt]') do?
Serg
@Sergio - This answer would require jQuery...and is definitely not the correct way to go about this :)
Nick Craver
It matches an input fields that contain '_txt' in their id
TheGeekYouNeed
You would use this for something like if you wanted to change the class of the textbox onclick using javascript. I wasn't thinking so simply as Nick down below :)
TheGeekYouNeed
@TheGeekYouNeed - It selects all IDs that *end* in `_txt`, `*=` would be contains.
Nick Craver
+2  A: 

You can give it a CSS class, like this:

<asp:TextBox ID="txtPais" runat="server" CssClass="textbox" />

Then just use add what you need in your CSS:

.textbox { color: red; }

The CssClass property doesn't get mangled like the ID and name attributes.

Nick Craver
Thanks! Much clearer answer. However it's not working as expected. I set the CssClass attribute, created the CSS rule; during testing while viewing source I can see that the CSS file is being correctly linked, but no change. I also notice the normal HTML code for the textbox doesn't have a reference to my css class at all. What would cause this?
Serg
@Sergio - Is the CssClass getting changed anywhere else? The HTML for my example above should render `class="textbox"` as a property on the `<input>`.
Nick Craver
OK, I added ANOTHER textbox to see if the testing server isn't relaying new information and that's the case. It's not showing the newest additions. How can I make sure that the testing server shows me the latest stuff? I mean the ASP.Net Development server.
Serg
@Sergio - that happens sometimes, either a server restart or a re-compile *usually* forces it to re-cache, if that doesn't work blow away the temporary files under your Microsot.Net\Framework folder (in the rare case it *really* won't let go).
Nick Craver
A: 

Why wouldn't you do this either:

input[type=text] { /* style */ } (standard)

or

input.text { /* style */ } (not as standard)

???

xanadont
That would effect all text boxes on any page the stylesheet is linked to. If that is what he wants then there is nothing wrong with that.
TheGeekYouNeed