Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validators and ClientIDMode issue (ASP.NET)

Tags:

c#

validation

ASP.NET 4.0 has introduced the property 'ClientIDMode', which allows one to specify how the html element's ids are rendered in the output html.

My project is currently set to 'Static' (the shortest / contains no hierarchy id's)

When using any validator (RequiredFieldValidator, RegularExpressionValidator...), unless the control it's validating explicitly has it's property ClientIDMode:AutoID I get the error:

Input parameter 'controlId' cannot be an empty string.

Is this the expected behaviour?

Edit: Being abit dumb with the error message, it wanted me to put an id on the Validator, which I obviously dont do (unless I need to reference it).

It still seems odd that it should fail because of this reason.

like image 383
maxp Avatar asked Oct 13 '10 10:10

maxp


1 Answers

I ran into this in a slightly different way: if my user control had ClientIDMode="Static", I received the error on the validators that existed within the control (they did not all have ID's).

One workaround is to switch ClientIDModes on the offending user control. Hope this helps!

like image 197
ChessWhiz Avatar answered Sep 28 '22 04:09

ChessWhiz