Solved

Change readonly property at runtime

Posted on 2004-08-17
3
367 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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