required field validator in Web custom control

Discussion in 'ASP .Net Web Controls' started by Sogescom, Jul 4, 2003.

  1. Sogescom

    Sogescom Guest

    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);
    }
     
    Sogescom, Jul 4, 2003
    #1
    1. Advertising

  2. Sogescom

    Teemu Keiski Guest

    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:


    "Sogescom" <> kirjoitti viestissä
    news:030801c3426d$5c4414e0$...
    > 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);
    > }
     
    Teemu Keiski, Jul 7, 2003
    #2
    1. Advertising

  3. 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" <>
    !Sender: "Sogescom" <>
    !Subject: required field validator in Web custom control
    !Date: Fri, 4 Jul 2003 13:46:36 -0700
    !Lines: 29
    !Message-ID: <030801c3426d$5c4414e0$>
    !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);
    !}
    !
     
    Yan-Hong Huang[MSFT], Jul 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jinsong Liu

    Required Field Validator Client side popup

    Jinsong Liu, Aug 14, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    5,510
    Guenther Liebowitz
    Aug 14, 2003
  2. Do
    Replies:
    3
    Views:
    4,425
    Mike Moore [MSFT]
    Oct 23, 2003
  3. vikasmalukani
    Replies:
    0
    Views:
    744
    vikasmalukani
    Sep 24, 2008
  4. Alex Shirley

    Check required field in custom validator

    Alex Shirley, Jul 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    155
    Alex Shirley
    Jul 13, 2004
  5. jr
    Replies:
    3
    Views:
    433
Loading...

Share This Page