Home All Groups Group Topic Archive Search About

How to set property "ReadOnly" on all TextBoxes on a WebForm

Author
20 Feb 2006 10:38 AM
Dan Kimhi
Hello,

I'm in the process of learning asp.net and WebForms.

Could somebody indicate how I can write code to control the properties of
the (TextBox) controls on a WebForm.?Thanks.

Dan Kimhi

Author
20 Feb 2006 12:42 PM
Christopher Reed
Use the Page_Load method in your
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."code-behind.

Show quoteHide quote
"Dan Kimhi" <d**@sof.fr> wrote in message
news:%23DrYHngNGHA.2036@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I'm in the process of learning asp.net and WebForms.
>
> Could somebody indicate how I can write code to control the properties of
> the (TextBox) controls on a WebForm.?Thanks.
>
> Dan Kimhi
>
Author
20 Feb 2006 8:01 PM
blackstaronline.net
txtbox1.readonly = True
txtbox2.readonly = True

or depending on the situation you could use;

txtbox1.enabled = False
txtbox2.enabled = False

or

txtbox1.visible = False
txtbox2.visible = False

You can do this in the

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
    txtbox1.readonly = True
    txtbox2.readonly = True
End Sub

Hope this helps,
Jeremy Reid
http://blackstaronline.net/hgtit
Author
21 Feb 2006 6:17 AM
Dan Kimhi
Thank you both for your reply.

I mean more like a recursive function that can find the TextBox on the Page
and change its property...

Dan


"blackstaronline.net" <jr***@blackstaronline.net> a écrit dans le message de
news: 1140463195.602259.73***@f14g2000cwb.googlegroups.com...
Show quoteHide quote
> txtbox1.readonly = True
> txtbox2.readonly = True
>
> or depending on the situation you could use;
>
> txtbox1.enabled = False
> txtbox2.enabled = False
>
> or
>
> txtbox1.visible = False
> txtbox2.visible = False
>
> You can do this in the
>
> Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>    txtbox1.readonly = True
>    txtbox2.readonly = True
> End Sub
>
> Hope this helps,
> Jeremy Reid
> http://blackstaronline.net/hgtit
>
Author
21 Feb 2006 12:37 PM
Christopher Reed
You can always use Page.Controls and loop through the controls on the page
and identifying each Textbox object.

But why do want to do this since this is adding extra code to your
application?  Please explain what you're trying to do.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

Show quoteHide quote
"Dan Kimhi" <d**@sof.fr> wrote in message
news:eHkMR6qNGHA.420@tk2msftngp13.phx.gbl...
> Thank you both for your reply.
>
> I mean more like a recursive function that can find the TextBox on the
> Page and change its property...
>
> Dan
Author
21 Feb 2006 5:06 PM
blackstaronline.net
I do it all the time. If the result from a dynamic drop down are used
to fill a 2nd dynamic drop down, I will make the 2nd drop down
Enabled=False until the OnSelectedItem change for the first drop down.
Sometimes a sacrifice in a few extra lines of code is necessary for
"ease of use" in your application.

Just my 2 cents.

Jeremy Reid
http://hgtit.com
Author
21 Feb 2006 9:52 PM
Dan Kimhi
Thank you all for helping.

I finally used the following:

Private Sub SetTextBoxes(ByVal bval As Boolean)

Dim c As Control

Dim childc As Control

For Each c In Page.Controls

For Each childc In c.Controls

If TypeOf childc Is TextBox Then

Dim t As TextBox = CType(childc, TextBox)

t.ReadOnly = bval

End If

Next

Next

End Sub



Dan  Kimhi





"blackstaronline.net" <jr***@blackstaronline.net> a écrit dans le message de
news: 1140541589.811798.303***@g14g2000cwa.googlegroups.com...
Show quoteHide quote
>I do it all the time. If the result from a dynamic drop down are used
> to fill a 2nd dynamic drop down, I will make the 2nd drop down
> Enabled=False until the OnSelectedItem change for the first drop down.
> Sometimes a sacrifice in a few extra lines of code is necessary for
> "ease of use" in your application.
>
> Just my 2 cents.
>
> Jeremy Reid
> http://hgtit.com
>