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

Custom Validator in a Datalist

P: n/a
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

Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Richard Payne wrote:
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 :)
--
jo inferis
Nov 18 '05 #2

P: n/a
Hi

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

Regards

"Jo Inferis" <in*****@NOSPAM.gotadsl.co.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Richard Payne wrote:
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 :)
--
jo inferis

Nov 18 '05 #3

P: n/a
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=z...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

Nov 18 '05 #4

P: n/a
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.
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:N1**************@cpmsftngxa06.phx.gbl...
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=z...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

Nov 18 '05 #5

P: n/a
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
Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.