required field validator in Web custom control

S

Sogescom

I tried to make a control with a label a text box and a
required fiel validator, but i always reiceved this error:

Unable to find control id 'FormField:Address1' referenced
by the 'ControlToValidate' property of ''.

What i'm doing wrong???

this is the to main method

protected override void CreateChildControls()
{
TextBox tbxAddress = new TextBox();
Label lblMessage = new Label();
RequiredFieldValidator req = new RequiredFieldValidator();
lblMessage.Text= "";
Controls.Add(lblMessage);
tbxAddress.ID = "FormField:Address1";
Controls.Add(tbxAddress);
req.ControlToValidate = tbxAddress.ID;
req.ErrorMessage = InvalidMessage ;
Controls.Add(req);

}
protected override void Render(HtmlTextWriter output)
{
EnsureChildControls();
base.Render(output);
}
 
T

Teemu Keiski

Try adding the TextBox with such ID that doesn't have ':' . Also did you
implement INamingContainer interface in your control? Implementing it would
be advisable.

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)
 
Y

Yan-Hong Huang[MSFT]

Hello,

I replied a same post yesterday. Based on my testing, if you removed
"FormField:" from the ID property of textbox, the code runs fine. It seems
that the problem is caused by colon.

If you have any follow up questions, just post them here.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
--------------------
!Content-Class: urn:content-classes:message
!From: "Sogescom" <[email protected]>
!Sender: "Sogescom" <[email protected]>
!Subject: required field validator in Web custom control
!Date: Fri, 4 Jul 2003 13:46:36 -0700
!Lines: 29
!Message-ID: <[email protected]>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNCbVxEDsj/xu6DSlimOxWDBv37yw==
!Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
!Path: cpmsftngxa09.phx.gbl
!Xref: cpmsftngxa09.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:3264
!NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
!
!I tried to make a control with a label a text box and a
!required fiel validator, but i always reiceved this error:
!
!Unable to find control id 'FormField:Address1' referenced
!by the 'ControlToValidate' property of ''.
!
!What i'm doing wrong???
!
!this is the to main method
!
!protected override void CreateChildControls()
!{
!TextBox tbxAddress = new TextBox();
!Label lblMessage = new Label();
!RequiredFieldValidator req = new RequiredFieldValidator();
!lblMessage.Text= "";
!Controls.Add(lblMessage);
!tbxAddress.ID = "FormField:Address1";
!Controls.Add(tbxAddress);
!req.ControlToValidate = tbxAddress.ID;
!req.ErrorMessage = InvalidMessage ;
!Controls.Add(req);
!
!}
!protected override void Render(HtmlTextWriter output)
!{
!EnsureChildControls();
!base.Render(output);
!}
!
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top