Change a Textbox to Multiline while maintaining CSS

Asked

Viewed 606 times

1

I have a web application with several Textboxes. However, I need some of them to stay with Multiline because of the text they will contain. Every time I make this change I lose CSS settings. From what I’ve researched it seems that Textbox becomes Textarea in Runtime.

So I needed to know how to maintain or even add CSS to that object in order to keep my back Colors, Fonts and Sizes.

Example of ASP:

  <asp:TextBox ID="txtCC"  runat="server" TextMode = "MultiLine"  Width="100%" CssClass="textArea" ReadOnly="True"></asp:TextBox><br />

Example of CSS

 .textArea 
{ 
    background-color:#EEEEEE;
    font-family: Verdana;
    font-size: 11px;
} 
  • Can you give us the code you’ve already created for this?

  • Edited to include code

  • does one more thing? take a look at the html that is generated on the page with the multiline and without the multiline, theoretically if you set a class to the textbox it should use it...

  • When he sees the generated code, he puts the textbox as textarea but ignores the CSS, hence my question....

1 answer

2

Creating a simple application, with the data informed in the question, one can see that the CSS is applied even using `Textmode="Multiline". So, probably the page is not finding the CSS file. See the following example, which shows the Default.aspx page.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .textArea
        {
            background-color: green;
            font-family: Verdana;
            font-size: 21px;
        }
    </style>
</head>
<body style="height: 3000px">
    <form id="form1" runat="server">
    <asp:TextBox ID="txtCC" runat="server" TextMode="MultiLine" Width="100%" CssClass="textArea"
        ReadOnly="True"></asp:TextBox><br />
    </form>
</body>
</html>

See that I put a green background color, to make it clear that the CSS application works. I also changed the font size to again highlight the style change.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.