By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,491 Members | 3,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,491 IT Pros & Developers. It's quick & easy.

Validator Positioning

P: n/a
Hi guys,

I've a small problem with validators.

I'm building a single .aspx file that handles all my form posts. I need to
be using ASP.NET validators ( or subclasses thereof ), so what i do to
overcome the fact that i don't really know what sort of input controls I'm
working with is this:

1) I've got the form description in xml, so I know all the fields I'm
expecting & their validators with whatever parameters.
2) I dynamically create an HtmlForm component
3) for-each field in my form, I instantiate a home-grown subclass of Input
control, feed it the request parameter & add it to the form.
4) for-each validator in the field, I instantiate the validator and do some
reflection tricks to set the parameters. Then , I add the validator to the
form controls, and I add the validator to the page validators collection.
5) last, I call Page.Validate()

... this all works wonderfully. Validation occurs just like it should, my
only problem is this:

Since, I've added the validators to the form - which is added dynamically
onto the page - the validators aren't positioned anywhere, so the error
message that gets printed, gets printed wherever it wants ! :D

What I though of doing to overcome thins, was to define an <asp:table> on
the page, add a row & cell per control (which is actually invisible ) and
add the validator to the same cell.So, logically, the validator should print
it's message inside the cell I put it ... unfortunately, validators can only
be added to a Form, and I've no idea how to tell the form to render it's
controls inside the table :?

Can anybody help out here ? ( boy, I hate GUIs !!! )

Thanks a lot,

Angel
O:]
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I think you are on the right track with using a Table control to organize
the layout of your inputs and validators. Validators are controls just like
any other control and can be placed within TableCell controls. For example
if I have a TableCell control named tableCell and a validator named
myValidator, I can do the following:

tableCell.Controls.Add(myValidator);

You will then still need to add the Validator to the Page.Validators
collection.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Angelos Karantzalis" <ak**********@agiltech.gr> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...
Hi guys,

I've a small problem with validators.

I'm building a single .aspx file that handles all my form posts. I need to
be using ASP.NET validators ( or subclasses thereof ), so what i do to
overcome the fact that i don't really know what sort of input controls I'm
working with is this:

1) I've got the form description in xml, so I know all the fields I'm
expecting & their validators with whatever parameters.
2) I dynamically create an HtmlForm component
3) for-each field in my form, I instantiate a home-grown subclass of Input
control, feed it the request parameter & add it to the form.
4) for-each validator in the field, I instantiate the validator and do
some
reflection tricks to set the parameters. Then , I add the validator to the
form controls, and I add the validator to the page validators collection.
5) last, I call Page.Validate()

.. this all works wonderfully. Validation occurs just like it should, my
only problem is this:

Since, I've added the validators to the form - which is added dynamically
onto the page - the validators aren't positioned anywhere, so the error
message that gets printed, gets printed wherever it wants ! :D

What I though of doing to overcome thins, was to define an <asp:table> on
the page, add a row & cell per control (which is actually invisible ) and
add the validator to the same cell.So, logically, the validator should
print
it's message inside the cell I put it ... unfortunately, validators can
only
be added to a Form, and I've no idea how to tell the form to render it's
controls inside the table :?

Can anybody help out here ? ( boy, I hate GUIs !!! )

Thanks a lot,

Angel
O:]

Nov 18 '05 #2

P: n/a
Unfortunately, a validator can only be added to the Controls collection of
an HtmlForm instance :(

I'm looking around the ValidationSummary class now, at least that shows the
error mesages in a "prettier" way, e.g. a bulleted list. Whatever happens,
I'll send a post to the group :]

Thanks for taking the time,

Angel
O:]

"Ben Lucas" <be*@nospam.solien.nospam.com> wrote in message
news:Ob********************@comcast.com...
I think you are on the right track with using a Table control to organize
the layout of your inputs and validators. Validators are controls just like any other control and can be placed within TableCell controls. For example if I have a TableCell control named tableCell and a validator named
myValidator, I can do the following:

tableCell.Controls.Add(myValidator);

You will then still need to add the Validator to the Page.Validators
collection.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Angelos Karantzalis" <ak**********@agiltech.gr> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...
Hi guys,

I've a small problem with validators.

I'm building a single .aspx file that handles all my form posts. I need to be using ASP.NET validators ( or subclasses thereof ), so what i do to
overcome the fact that i don't really know what sort of input controls I'm working with is this:

1) I've got the form description in xml, so I know all the fields I'm
expecting & their validators with whatever parameters.
2) I dynamically create an HtmlForm component
3) for-each field in my form, I instantiate a home-grown subclass of Input control, feed it the request parameter & add it to the form.
4) for-each validator in the field, I instantiate the validator and do
some
reflection tricks to set the parameters. Then , I add the validator to the form controls, and I add the validator to the page validators collection .. 5) last, I call Page.Validate()

.. this all works wonderfully. Validation occurs just like it should, my
only problem is this:

Since, I've added the validators to the form - which is added dynamically onto the page - the validators aren't positioned anywhere, so the error
message that gets printed, gets printed wherever it wants ! :D

What I though of doing to overcome thins, was to define an <asp:table> on the page, add a row & cell per control (which is actually invisible ) and add the validator to the same cell.So, logically, the validator should
print
it's message inside the cell I put it ... unfortunately, validators can
only
be added to a Form, and I've no idea how to tell the form to render it's
controls inside the table :?

Can anybody help out here ? ( boy, I hate GUIs !!! )

Thanks a lot,

Angel
O:]


Nov 18 '05 #3

P: n/a
Well, the ValidationSummary approach worked fine :D

I've added the control inside a table in the page, and then set the Display
property of all validators to None.
In that way, after validation has finished,any error messages are displayed
inside the ValidationSummary control, which is positioned using the table
that surrounds it ;]

Angel
O:]

"Ben Lucas" <be*@nospam.solien.nospam.com> wrote in message
news:Ob********************@comcast.com...
I think you are on the right track with using a Table control to organize
the layout of your inputs and validators. Validators are controls just like any other control and can be placed within TableCell controls. For example if I have a TableCell control named tableCell and a validator named
myValidator, I can do the following:

tableCell.Controls.Add(myValidator);

You will then still need to add the Validator to the Page.Validators
collection.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"Angelos Karantzalis" <ak**********@agiltech.gr> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...
Hi guys,

I've a small problem with validators.

I'm building a single .aspx file that handles all my form posts. I need to be using ASP.NET validators ( or subclasses thereof ), so what i do to
overcome the fact that i don't really know what sort of input controls I'm working with is this:

1) I've got the form description in xml, so I know all the fields I'm
expecting & their validators with whatever parameters.
2) I dynamically create an HtmlForm component
3) for-each field in my form, I instantiate a home-grown subclass of Input control, feed it the request parameter & add it to the form.
4) for-each validator in the field, I instantiate the validator and do
some
reflection tricks to set the parameters. Then , I add the validator to the form controls, and I add the validator to the page validators collection. 5) last, I call Page.Validate()

.. this all works wonderfully. Validation occurs just like it should, my
only problem is this:

Since, I've added the validators to the form - which is added dynamically onto the page - the validators aren't positioned anywhere, so the error
message that gets printed, gets printed wherever it wants ! :D

What I though of doing to overcome thins, was to define an <asp:table> on the page, add a row & cell per control (which is actually invisible ) and add the validator to the same cell.So, logically, the validator should
print
it's message inside the cell I put it ... unfortunately, validators can
only
be added to a Form, and I've no idea how to tell the form to render it's
controls inside the table :?

Can anybody help out here ? ( boy, I hate GUIs !!! )

Thanks a lot,

Angel
O:]


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.