Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6840043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:47:32+00:00 2026-05-26T23:47:32+00:00

I have a TextBox control and I want the rendered input element to have

  • 0

I have a TextBox control and I want the rendered input element to have the readonly attribute with value readonly:

<input type="text" readonly="readonly" />

I could do it in code-behind using the following code:

textBox.Attributes["readonly"] = "readonly"

but I’d rather have all my control attributes and their values in my markup. Can I do it in the markup?
A solution could be to extend the TextBox control, but this feels overly complicated for the intended result.

I want to be able to change the value client-side with javascript, and read the value server-side during postbacks. Please note that putting the TextBox.ReadOnly property to True would not solve the issue, as this also causes the server to ignore the TextBox’ value on postbacks. (MSDN.) I simply want the readonly behavior from the browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:47:33+00:00Added an answer on May 26, 2026 at 11:47 pm

    It seems you can’t do it cleanly in the markup without getting ASP.NET’s ReadOnly side effects.

    However, you could use inline code, although it looks ugly.

    <asp:TextBox runat="server" ID="textBox" />
    <% textBox.Attributes["readonly"] = "readonly"; %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows forms app with a textbox control that I want to
I have a TextBox and a Popup control. I want the Popup.IsOpen property to
I am using asp.net MVC. I have control like <%= Html.TextBox(username) %> I want
Say i have a TextBox control inside of a ListView where the text is
I have large text in System.Windows.Forms.TextBox control in my form (winforms), vs 2008. I
I want to have a textbox control that suggests and append values from a
I want to create custom Textbox control in asp.net.But i have one doubt when
I have a textbox asp.net server control. I am modifying the value of textbox
i have a TextBox control on my masterpage <asp:TextBox ID=txtSubject runat=server Width=280px CssClass=formtxt onblur=if(this.value=='')
I'm creating a login page. I want to create ASP.NET TextBox controls that have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.