Validator Positioning

  • Thread starter Angelos Karantzalis
  • Start date
A

Angelos Karantzalis

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:]
 
B

Ben Lucas

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.
 
A

Angelos Karantzalis

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 said:
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 said:
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:]
 
A

Angelos Karantzalis

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 said:
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 said:
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:]
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top