Custom Controls and ASP.NET Validation (Client Side) (MORE)

It turns out that when I said:

It turns out that when I said:
Turns out it is as simple as adding [ValidationPropertyAttribute(“­Text”)] to your class definition for the custom control. That’s easy!
it really wasn’t that easy, at least to get client side support for validators to work.

After a lot of research, and a bunch of looking through the page output I figured out what must be done.

If you have a custom server control and it is named “MyDateTime1”, then the HTML element that you want to check in your client side validation must also be named “MyDateTime1”. In my control, I would output a bunch of different elemnts, using things like ClientID + “_textbox” and ClientID + “_Icon” etc… All I had to do was make sure the textbox (which is what I wanted to run the client side validation against) was named simply this.ClientID and presto!

It really isn’t that easy.

I think this worked before because I was created HTML elements, and not ASP.NET Webcontrols. I am trying to basically do the same thing, and let me tell you, it isn’t working. I am getting an error saying that there are more than 1 control w/ the same name. The problem (I believe) is that container control is registered w/, and when I dynamically add an textbox with the same name as the parent control, it flips out. With my other control I was just adding an HTML textbox.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s