Solved

Change readonly property at runtime

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

17 Experts available now in Live!

Get 1:1 Help Now