CustomValidator added at runtime --> server-side validation dropped

Discussion in 'ASP .Net Web Controls' started by peshrad, Jul 21, 2004.

  1. peshrad

    peshrad Guest

    Hi !

    I'm using Visual Studio 2000,
    Win2K, IE 6, .NET 1.1.

    I'm experimenting with an extremely simple ASP.NET web application.

    When I add a CustomValidator to the designer by drag&drop,
    I can accomplish both client-side and subsequent server-side validation.
    At run-time, when I press my submit button,
    first my JavaScript function is called for validation,
    later my C# event handler is called in the server-side code.

    However, when I add the CustomValidator at run-time,
    only client-side validation works.

    How can I fix this problem ?
    Here comes the code that creates the CustomValidator at run-time.
    The function cv_2_ServerValidate is never called later.

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    CustomValidator cv = new CustomValidator();

    cv.ID = "cv_2";
    cv.ControlToValidate = "TextBox1";
    cv.ErrorMessage = "Another input error!";
    cv.ServerValidate +=new
    ServerValidateEventHandler(cv_2_ServerValidate);
    cv.ClientValidationFunction = "doClientValidation";

    TextBox1.Parent.Controls.Add(cv);
    }
    }

    Your kind advice would be appreciated.

    Peter
     
    peshrad, Jul 21, 2004
    #1
    1. Advertising

  2. peshrad

    peshrad Guest

    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if(!IsPostBack)
    > {
    > CustomValidator cv = new CustomValidator();
    >
    > cv.ID = "cv_2";
    > cv.ControlToValidate = "TextBox1";
    > cv.ErrorMessage = "Another input error!";
    > cv.ServerValidate +=new
    > ServerValidateEventHandler(cv_2_ServerValidate);
    > cv.ClientValidationFunction = "doClientValidation";
    >
    > TextBox1.Parent.Controls.Add(cv);
    > }
    > }


    Just drop the condition !IsPostBack
    for executing the set-up of the CustomValidator !
     
    peshrad, Jul 22, 2004
    #2
    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. Matt
    Replies:
    14
    Views:
    4,108
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. Mo
    Replies:
    3
    Views:
    2,184
    Mo hariri
    Jan 15, 2005
  3. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    754
    Kevin Spencer
    Jun 2, 2005
  4. Next

    CustomValidator server-side

    Next, Jan 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    166
  5. Mo

    Server side CustomValidator and FormView

    Mo, Mar 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    145
Loading...

Share This Page