locked
How To Apply Two CssClass In One Textbox RRS feed

  • Question

  • User2033107836 posted

    Hello

    I Have One Textbox and in that i want to bind two CssClass 

    For example CssClass="Validate" and CssClass="Caluclate"

    How To bind both in one textbox in asp.net 2.0 C#

    Thanking You

    Friday, April 20, 2018 9:41 AM

Answers

  • User-369506445 posted

    hi

    you can use jquery add several css class to your controls.

    I create a sample that when click on your button the textbox background color and text color be change

    please try below code :

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style>
            .backgroundColor {
                background-color: red;
            }
            .textColor {
                color: blue;
            }
        </style>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script>
            $(document).ready(function () {
                $("button").click(function () {
                    $("#txt").addClass("backgroundColor");
                    $("#txt").addClass("textColor");
                    
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:TextBox runat="server" ID="txt" Text="test css color"></asp:TextBox>
       <button type="button">Button</button>
        </div>
        </form>
    </body>
    </html>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 20, 2018 10:02 AM