in

But it works on my PC!

The random thoughts of Richard Fennell on technology and software development

This Blog

Syndication

'Unable to find control' when programmatically adding ASP.NET validation controls

I have been building a webpart that needs client side validation. I kept getting the error:

"Unable to find control id txtNotes referenced by the 'ControlToValidate' property"

Now most of the posts say just use the command to get the 'real' ID at runtime

this.rfvNotes.ControlToValidate = this.txtNotes.ClientID;

But this did not work, in the end the form I found worked was:

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.txtNotes.ID = "txtNotes";
        this.rfvNotes.ControlToValidate = this.txtNotes.ID;
        this.rfvNotes.Enabled = true;
        this.rfvNotes.Text = "* Required";
    }

The key step was to set the textbox ID manually, it seems that if this is not done it is the root of the error.

Published Jul 23 2008, 11:11 PM by Richard
Filed under:

Comments

 

MartinRandall said:

Looks good. Did you try UniqueID?

July 24, 2008 10:03 AM
 

Richard said:

I didn't, might have helped. I usually find ClientID is enough, but not this time.

July 24, 2008 3:38 PM
Black Marble 2004-2009
Powered by Community Server (Commercial Edition), by Telligent Systems