[newbie] document.all collection equivalent

H

HP

Hi,

I have a form in asp .net with several inputs. I dont wanna specify a
validation rule for every input, but for all of them, like this in
javascript:
for (var i=0;i<20;i++) { if (document.forms("F").elements(i).value.length <
3) ... }
can u tell me how can I do the same and access all of them in asp .net?
 
D

Daniel Fisher\(lennybacon\)

can u tell me how can I do the same and access all of them in asp .net?
So you mean in serverside code right?

[C#]

for(int i=0; i<this.Page.Controls.Count; i++)
{
if(this.Page.Controls is TextBox)
{
//...
}
//...

}
 
H

HP

Thanks, It works now but I have another problem. I can't access the Text
property of my TextBoxes. see:
Form1.Controls.Text
returns:
CS0117: 'System.Web.UI.Control' does not contain a definition for 'Text'.

yes It doesn't. so what should I do?

Actually I mixed up with ASP. NET, I used to work with ASP, it was so easy
to work with HTML elements and collections by JavaScript but now that I just
switched to learn ASP.NET, I always I have a problem. working with asp.net
(server-side) controls isn't as easy as what I've expected. even I don't
know is it better to use asp.net controls to build a web Form or it's better
to have a simple html form like before? another thing in asp .net that was
interesting for me is RangeValidator which was useless to me. I prefer to
write my own validation rule by a simple script, no need to RangeValidator
which is restricted to a rule of MaximumValue and MinimumValue.

Thanks a lot and sorry for my bad english.

Daniel Fisher(lennybacon) said:
can u tell me how can I do the same and access all of them in asp .net?
So you mean in serverside code right?

[C#]

for(int i=0; i<this.Page.Controls.Count; i++)
{
if(this.Page.Controls is TextBox)
{
//...
}
//...

}



--
Daniel Fisher(lennybacon)
MCP ASP.NET C#
Blog: http://www.lennybacon.com/


HP said:
Hi,

I have a form in asp .net with several inputs. I dont wanna specify a
validation rule for every input, but for all of them, like this in
javascript:
for (var i=0;i<20;i++) { if (document.forms("F").elements(i).value.length
<
3) ... }
can u tell me how can I do the same and access all of them in asp .net?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top