Custom Validator in a Datalist

R

Richard Payne

Hi

This is probably a newbie question but I can't seem to find a clear answer
to the problem I have.

I have created a Custom Validator control on my webform that works fine, but
when I put the control in to the header section of my datalist it doesn't
work, the ServerValidate event doesn't fire. I presume that I haven't wirded
it up correctly.

I am working in C#

Regards
 
J

Jo Inferis

Richard said:
This is probably a newbie question but I can't seem to find a clear
answer to the problem I have.
I wouldn't worry about that, it's usually more stupid *not* to ask the
question...
I have created a Custom Validator control on my webform that works
fine, but when I put the control in to the header section of my
datalist it doesn't work, the ServerValidate event doesn't fire. I
presume that I haven't wirded it up correctly.
I've just done something fairly similar to this, and I think it rather
depends on how you're wiring up the validator. Within the main body of the
web form the validator is probably in the same level of the hierarchy as the
control it's validating so it's easy enough to just add
ControlToValidate="myControl". When the validator is contained by another
object (such as the header portion of a datalist, you'll have to fully
qualify the control to validate by finding it programmatically first (I'm
not sure exactly how to do that in the attribute of the tag).

HTH :)
 
R

Richard Payne

Hi

As it is a custom validator its not linked to any specific control.

Regards
 
S

Steven Cheng[MSFT]

Hi Richard,

As for the Validator's problem when we use them as nested controls of some
certain Template Controls such as
DataGrid, DataList ........

As Jo has mentioned, the Validator control's "ControltoValidate" property
is a string value which represent the Control(need to validate)'s ID. And
the restriction is that the validation control and the Control want to
validate much in the same control hierarchy. For example, if we put a
Validation control in a DataGrid Template control (in ItemTemplate) , then
,the "ControltoValidate" must set to a control's ID which is in the same
template with it so that when the page is rendered out at runtime, the
validate control 's validation code can locate the control correctly.
In addition, for detailed reference, here is a former thread discussing on
the similiar problem:

http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&threadm=DVLfEY5FEHA.61
2%40cpmsftngxa06.phx.gbl&rnum=1&prev=/groups%3Fq%3DDataGrid%2Bvalidation%2B%
2522jeffrey%2BTan%2522%26hl%3Dzh-CN%26lr%3D%26ie%3DUTF-8%26selm%3DDVLfEY5FEH
A.612%2540cpmsftngxa06.phx.gbl%26rnum%3D1

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
R

Richard Payne

Hi

Thanks for your reply

I am afraid I still can't get the control to work the way I want to. Its
probably a case me being a newbie to this and not fully understanding how it
all works espically when it comes to nested controls etc.

What I want to do is create a custom validate control that fires when the
datalist has no items in it and I would like to put this control in the
header template of the datalist. I only have a label and 'Add' button in the
header template so I am not sure which control to link the validator to.

If anybody has some code that does this that would be great.

Regards

Richard.
 
S

Steven Cheng[MSFT]

Hi Richard,

From your further description. It seems that what your validation control
do is to check whether the DataList has item in it, yes? I think this is
just a normal custom control, needn't create it as a validation control.
Since you use it to check the
DataList control, do you do the check via clienside code or serverside?

I think you can put a certain string property for the control which used to
hold the Control Id of the DataList it will need to validate. Do you think
so?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top