Search code examples
asp.nethtmlcss

Unable to add attribute to html text input


I have ASP.NET web form there is html input text:

<input type="text" class="input" runat="server" id="txtFirstName"/>

i want to change width this way but it does not works

protected void btnRegister_Click(object sender, EventArgs e) 
    {
        if (txtFirstName.Value.Length > 15)
        {
            txtFirstName.Attributes.Add("width", "15px");
        }
    }

p.s. i have access on this text input. Im inputting more than 15 characters and if works good


Solution

  • txtFirstName.style["width"]= "15px";