473,418 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Make a control Readonly using the controls Collection

GP
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;
}

Nov 18 '05 #1
10 7203
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" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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;
}

Nov 18 '05 #2
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" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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;
}

Nov 18 '05 #3
"GP" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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
Nov 18 '05 #4
GP
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" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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;
}


Nov 18 '05 #5
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" <GP@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
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" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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;
}


Nov 18 '05 #6
GP
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" <GP@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
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" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
> 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;
> }
>
>
>


Nov 18 '05 #7
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" <GP@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
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" <GP@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
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" <GP@discussions.microsoft.com> wrote in message
> news:C0**********************************@microsof t.com...
> > 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;
> > }
> >
> >
> >
>
>
>


Nov 18 '05 #8
GP
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" <GP@discussions.microsoft.com> wrote in message
news:7D**********************************@microsof t.com...
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" <GP@discussions.microsoft.com> wrote in message
news:BD**********************************@microsof t.com...
> 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" <GP@discussions.microsoft.com> wrote in message
> > news:C0**********************************@microsof t.com...
> > > 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;
> > > }
> > >
> > >
> > >
> >
> >
> >


Nov 18 '05 #9
Hello John,

This may work too...

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

--
Matt Berther
http://www.mattberther.com
"GP" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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


Nov 18 '05 #10
I've done it today with a client script. You can place this snippet at the
botton of the page or within a funcion you call when you want. You can write
it in the aspx file or render it exactly where you want.

this is a sample, hope it helps:

<script language="javascript">
<!--
var inputs = document.getElementsByTagName("INPUT");
var selects = document.getElementsByTagName("SELECT");

for (var i = 0;i<inputs.length;i++)
{
if ( (inputs[i].type == "text") && (inputs[i].disabled) )
{

inputs[i].disabled = false;
inputs[i].readOnly = true;
inputs[i].className = "Normal";
inputs[i].tabIndex = -1;

}
}

for (var i = 0;i<selects.length;i++)
{
selects[i].className = "Normal";
selects[i].tabIndex = -1;
selects[1].readOnly = true;
}
//-->
</script>

"GP" <GP@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
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;
}

Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
3
by: sean | last post by:
Hi There, I am trying to display some textboxes on my page, When I run the code the textbox is written to the page (when I view source) but not to the screen. Could someone tell me if I have the...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
1
by: ANDRES BECERRA | last post by:
Herfried K. Wagner was kind enough to point me to the PropertyGrid control http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformspropertygridclasstopic.asp I have found a few...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
0
by: Mike | last post by:
Hi. I can't figure out why a button's click event is not firing in a templated control I've created (first time I've tried creating one). Please can someone help? On a point of lesser importance,...
0
by: Christian | last post by:
Hi all, i already posted this in dotnet.vb.controls but i need some help, so i cant wait... I have written a web control library and have some problems with it. The Library contains only two...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.