Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Make a control Readonly using the controls Collection

Reply
Thread Tools

Make a control Readonly using the controls Collection

 
 
=?Utf-8?B?R1A=?=
Guest
Posts: n/a
 
      09-28-2004
Is it possible to iterate through all the controls collection and make the
textboxes alone as read only.I don't see a readonly property for the
Control.Can some one help me in this context?
I want to do something like this below.But I get a message Readonly is not
valid property.
foreach (Control ctl in pnlBenefits.Controls)
{
if (ctl is TextBox)
ctl.ReadOnly=false;
}



 
Reply With Quote
 
 
 
 
Curt_C [MVP]
Guest
Posts: n/a
 
      09-28-2004
I believe what you are after is:
..GetType()


--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"GP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is it possible to iterate through all the controls collection and make the
> textboxes alone as read only.I don't see a readonly property for the
> Control.Can some one help me in this context?
> I want to do something like this below.But I get a message Readonly is not
> valid property.
> foreach (Control ctl in pnlBenefits.Controls)
> {
> if (ctl is TextBox)
> ctl.ReadOnly=false;
> }
>
>
>



 
Reply With Quote
 
 
 
 
Hermit Dave
Guest
Posts: n/a
 
      09-28-2004
why dont you do a explicit typecast and then get its readonly property
foreach (Control ctl in pnlBenefits.Controls)
{
if (ctl is TextBox)
{
((TextBox)ctl).ReadOnly = false;
}
}

i think this should do the job
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is it possible to iterate through all the controls collection and make the
> textboxes alone as read only.I don't see a readonly property for the
> Control.Can some one help me in this context?
> I want to do something like this below.But I get a message Readonly is not
> valid property.
> foreach (Control ctl in pnlBenefits.Controls)
> {
> if (ctl is TextBox)
> ctl.ReadOnly=false;
> }
>
>
>



 
Reply With Quote
 
=?Utf-8?B?R1A=?=
Guest
Posts: n/a
 
      09-28-2004
Hi Hermit Dave,

Thanks for you response.
This time it didn't error me out, but none of my text boxes is set to
readonly.
My text boxes are declared using System.Web.UI.WebControls.TextBox,Is it
considered of Type TextBox too while using the Controls iteration.

Thanks
GP


"Hermit Dave" wrote:

> why dont you do a explicit typecast and then get its readonly property
> foreach (Control ctl in pnlBenefits.Controls)
> {
> if (ctl is TextBox)
> {
> ((TextBox)ctl).ReadOnly = false;
> }
> }
>
> i think this should do the job
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "GP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Is it possible to iterate through all the controls collection and make the
> > textboxes alone as read only.I don't see a readonly property for the
> > Control.Can some one help me in this context?
> > I want to do something like this below.But I get a message Readonly is not
> > valid property.
> > foreach (Control ctl in pnlBenefits.Controls)
> > {
> > if (ctl is TextBox)
> > ctl.ReadOnly=false;
> > }
> >
> >
> >

>
>
>

 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      09-28-2004
"GP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is it possible to iterate through all the controls collection and make the
> textboxes alone as read only.I don't see a readonly property for the
> Control.Can some one help me in this context?
> I want to do something like this below.But I get a message Readonly is not
> valid property.

foreach (Control ctl in pnlBenefits.Controls)
{
if (ctl is TextBox)
{
TextBox txt = (TextBox) ctl;
txt.ReadOnly=false;
}
}


-----
John Saunders


 
Reply With Quote
 
Hermit Dave
Guest
Posts: n/a
 
      09-28-2004
Yeap unless you have another control with the name TextBox it should map to
System.Web.UI.WebControls.TextBox

Get into Debug mode. put in a break point and see if its getting executed.
also try setting Enabled property to false.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Hermit Dave,
>
> Thanks for you response.
> This time it didn't error me out, but none of my text boxes is set to
> readonly.
> My text boxes are declared using System.Web.UI.WebControls.TextBox,Is it
> considered of Type TextBox too while using the Controls iteration.
>
> Thanks
> GP
>
>
> "Hermit Dave" wrote:
>
> > why dont you do a explicit typecast and then get its readonly property
> > foreach (Control ctl in pnlBenefits.Controls)
> > {
> > if (ctl is TextBox)
> > {
> > ((TextBox)ctl).ReadOnly = false;
> > }
> > }
> >
> > i think this should do the job
> > --
> >
> > Regards,
> >
> > Hermit Dave
> > (http://hdave.blogspot.com)
> > "GP" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Is it possible to iterate through all the controls collection and make

the
> > > textboxes alone as read only.I don't see a readonly property for the
> > > Control.Can some one help me in this context?
> > > I want to do something like this below.But I get a message Readonly is

not
> > > valid property.
> > > foreach (Control ctl in pnlBenefits.Controls)
> > > {
> > > if (ctl is TextBox)
> > > ctl.ReadOnly=false;
> > > }
> > >
> > >
> > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?R1A=?=
Guest
Posts: n/a
 
      09-28-2004
Thanks for your responses.
When I set to readonly it didn't work.Still I am able to edit the controls.
But when I set the control enabled=false.I see the text boxes disabled.
But I want the text box to be read only,so that I can get the values in the
viewstate.
foreach (Control ctl in pnlBenefits.Controls)
{
s= ctl.GetType().Name;
if (s == "TextBox")
{
((TextBox)ctl).ReadOnly = false;
}
}
}
Even I tried TextBox txt = (TextBox) ctl;
txt.ReadOnly=false;

Thanks
GP

"Hermit Dave" wrote:

> Yeap unless you have another control with the name TextBox it should map to
> System.Web.UI.WebControls.TextBox
>
> Get into Debug mode. put in a break point and see if its getting executed.
> also try setting Enabled property to false.
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "GP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Hermit Dave,
> >
> > Thanks for you response.
> > This time it didn't error me out, but none of my text boxes is set to
> > readonly.
> > My text boxes are declared using System.Web.UI.WebControls.TextBox,Is it
> > considered of Type TextBox too while using the Controls iteration.
> >
> > Thanks
> > GP
> >
> >
> > "Hermit Dave" wrote:
> >
> > > why dont you do a explicit typecast and then get its readonly property
> > > foreach (Control ctl in pnlBenefits.Controls)
> > > {
> > > if (ctl is TextBox)
> > > {
> > > ((TextBox)ctl).ReadOnly = false;
> > > }
> > > }
> > >
> > > i think this should do the job
> > > --
> > >
> > > Regards,
> > >
> > > Hermit Dave
> > > (http://hdave.blogspot.com)
> > > "GP" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Is it possible to iterate through all the controls collection and make

> the
> > > > textboxes alone as read only.I don't see a readonly property for the
> > > > Control.Can some one help me in this context?
> > > > I want to do something like this below.But I get a message Readonly is

> not
> > > > valid property.
> > > > foreach (Control ctl in pnlBenefits.Controls)
> > > > {
> > > > if (ctl is TextBox)
> > > > ctl.ReadOnly=false;
> > > > }
> > > >
> > > >
> > > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Hermit Dave
Guest
Posts: n/a
 
      09-28-2004
i think it could be based on rendering of the textbox. at the end of the day
its the browser that acts on the html attribute in the element and makes it
readonly.
with enabled = false i think you cannot do anything with the instance. ie no
modifications cant even get the focus. you still have access to the object
and the viewstate etc from serverside. The enabled = false is only for
client side rendering.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"GP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for your responses.
> When I set to readonly it didn't work.Still I am able to edit the

controls.
> But when I set the control enabled=false.I see the text boxes disabled.
> But I want the text box to be read only,so that I can get the values in

the
> viewstate.
> foreach (Control ctl in pnlBenefits.Controls)
> {
> s= ctl.GetType().Name;
> if (s == "TextBox")
> {
> ((TextBox)ctl).ReadOnly = false;
> }
> }
> }
> Even I tried TextBox txt = (TextBox) ctl;
> txt.ReadOnly=false;
>
> Thanks
> GP
>
> "Hermit Dave" wrote:
>
> > Yeap unless you have another control with the name TextBox it should map

to
> > System.Web.UI.WebControls.TextBox
> >
> > Get into Debug mode. put in a break point and see if its getting

executed.
> > also try setting Enabled property to false.
> >
> > --
> >
> > Regards,
> >
> > Hermit Dave
> > (http://hdave.blogspot.com)
> > "GP" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi Hermit Dave,
> > >
> > > Thanks for you response.
> > > This time it didn't error me out, but none of my text boxes is set to
> > > readonly.
> > > My text boxes are declared using System.Web.UI.WebControls.TextBox,Is

it
> > > considered of Type TextBox too while using the Controls iteration.
> > >
> > > Thanks
> > > GP
> > >
> > >
> > > "Hermit Dave" wrote:
> > >
> > > > why dont you do a explicit typecast and then get its readonly

property
> > > > foreach (Control ctl in pnlBenefits.Controls)
> > > > {
> > > > if (ctl is TextBox)
> > > > {
> > > > ((TextBox)ctl).ReadOnly = false;
> > > > }
> > > > }
> > > >
> > > > i think this should do the job
> > > > --
> > > >
> > > > Regards,
> > > >
> > > > Hermit Dave
> > > > (http://hdave.blogspot.com)
> > > > "GP" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > Is it possible to iterate through all the controls collection and

make
> > the
> > > > > textboxes alone as read only.I don't see a readonly property for

the
> > > > > Control.Can some one help me in this context?
> > > > > I want to do something like this below.But I get a message

Readonly is
> > not
> > > > > valid property.
> > > > > foreach (Control ctl in pnlBenefits.Controls)
> > > > > {
> > > > > if (ctl is TextBox)
> > > > > ctl.ReadOnly=false;
> > > > > }
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?R1A=?=
Guest
Posts: n/a
 
      09-29-2004
Thanks for you answer
"Hermit Dave" wrote:

> i think it could be based on rendering of the textbox. at the end of the day
> its the browser that acts on the html attribute in the element and makes it
> readonly.
> with enabled = false i think you cannot do anything with the instance. ie no
> modifications cant even get the focus. you still have access to the object
> and the viewstate etc from serverside. The enabled = false is only for
> client side rendering.
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "GP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Thanks for your responses.
> > When I set to readonly it didn't work.Still I am able to edit the

> controls.
> > But when I set the control enabled=false.I see the text boxes disabled.
> > But I want the text box to be read only,so that I can get the values in

> the
> > viewstate.
> > foreach (Control ctl in pnlBenefits.Controls)
> > {
> > s= ctl.GetType().Name;
> > if (s == "TextBox")
> > {
> > ((TextBox)ctl).ReadOnly = false;
> > }
> > }
> > }
> > Even I tried TextBox txt = (TextBox) ctl;
> > txt.ReadOnly=false;
> >
> > Thanks
> > GP
> >
> > "Hermit Dave" wrote:
> >
> > > Yeap unless you have another control with the name TextBox it should map

> to
> > > System.Web.UI.WebControls.TextBox
> > >
> > > Get into Debug mode. put in a break point and see if its getting

> executed.
> > > also try setting Enabled property to false.
> > >
> > > --
> > >
> > > Regards,
> > >
> > > Hermit Dave
> > > (http://hdave.blogspot.com)
> > > "GP" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Hi Hermit Dave,
> > > >
> > > > Thanks for you response.
> > > > This time it didn't error me out, but none of my text boxes is set to
> > > > readonly.
> > > > My text boxes are declared using System.Web.UI.WebControls.TextBox,Is

> it
> > > > considered of Type TextBox too while using the Controls iteration.
> > > >
> > > > Thanks
> > > > GP
> > > >
> > > >
> > > > "Hermit Dave" wrote:
> > > >
> > > > > why dont you do a explicit typecast and then get its readonly

> property
> > > > > foreach (Control ctl in pnlBenefits.Controls)
> > > > > {
> > > > > if (ctl is TextBox)
> > > > > {
> > > > > ((TextBox)ctl).ReadOnly = false;
> > > > > }
> > > > > }
> > > > >
> > > > > i think this should do the job
> > > > > --
> > > > >
> > > > > Regards,
> > > > >
> > > > > Hermit Dave
> > > > > (http://hdave.blogspot.com)
> > > > > "GP" <(E-Mail Removed)> wrote in message
> > > > > news:(E-Mail Removed)...
> > > > > > Is it possible to iterate through all the controls collection and

> make
> > > the
> > > > > > textboxes alone as read only.I don't see a readonly property for

> the
> > > > > > Control.Can some one help me in this context?
> > > > > > I want to do something like this below.But I get a message

> Readonly is
> > > not
> > > > > > valid property.
> > > > > > foreach (Control ctl in pnlBenefits.Controls)
> > > > > > {
> > > > > > if (ctl is TextBox)
> > > > > > ctl.ReadOnly=false;
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Matt Berther
Guest
Posts: n/a
 
      09-29-2004
Hello John,

This may work too...

foreach (TextBox tb in pnlBenefits.Controls)
{
tb.ReadOnly = false;
}

--
Matt Berther
http://www.mattberther.com

> "GP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> Is it possible to iterate through all the controls collection and
>> make the
>> textboxes alone as read only.I don't see a readonly property for the
>> Control.Can some one help me in this context?
>> I want to do something like this below.But I get a message Readonly
>> is not
>> valid property.

> foreach (Control ctl in pnlBenefits.Controls)
> {
> if (ctl is TextBox)
> {
> TextBox txt = (TextBox) ctl;
> txt.ReadOnly=false;
> }
> }
> -----
> John Saunders


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count == 0) Chad Scharf ASP .Net 3 10-18-2007 03:53 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
.Net 2.0 : Smart tags and Readonly Collection Property adlionel ASP .Net Building Controls 0 11-10-2005 11:15 AM
Collection Readonly Greg -- ASP .Net Web Services 0 07-25-2005 02:15 PM
ASP.NET Readonly panel function with readonly checkbox, readonly radiobutton Jonathan Hyatt ASP .Net Web Controls 1 06-08-2004 07:42 PM



Advertisments