Solved

Change readonly property at runtime

Posted on 2004-08-17
3
371 Views
Last Modified: 2008-03-17
i need to be able to set the readonly property of a textbox at run time. I can see that this property is part of the html. Can you give me an example in vb.net as to how i code this. Thank you...Glee
0
Comment
Question by:GleeFinnegan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 400 total points
ID: 11825589
In your Page_Load() event check the IsPostBack property of the Page object.  If it is false, set the ReadOnly property to true.  The following assumes a TextBox server control named txtTest is on the page.

If Page.IsPostBack = False Then
     txtTest.ReadOnly = False
End If

You should then see the readonly attribute in the <INPUT> element that is rendered as HTML when the page shows in the browser.

John
0
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 100 total points
ID: 11825938
Hi there,
if you are using an ASP TextBox (one from the WebForms tab in the ToolBox), just use..
TextBox1.ReadOnly = True/False

if you are using an HTML TextField (one from the HTML tab in the ToolBox), first right click on it and make it "Run At Server",  assign some ID to it, say Text1. Then set the readonly attribute to true/false.
        Text1.Attributes.Add("readonly", "true")

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/readonly_1.asp

-Baan
0
 

Author Comment

by:GleeFinnegan
ID: 11831295
Thank you both for your suggestions. The first one is the one that is appropriate for my situation. The second one may be useful in the future. Glee
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question