Solved

Change readonly property at runtime

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now