CustomValidator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stan SR

    #1

    CustomValidator

    Hi,

    I have a web user control that contains 3 dropdownlists
    it's a date selector, so one contains the days, one the months and the last
    the years.
    Each of them starts with a blank value.


    I want to control if the date is valid or blank (that means all the
    dropdownlist have a blank value).

    I need to add a customvalidator but I don't know on which control I have to
    set it.

    I create a javascript function to check the date.
    here's the script
    var client="<%=Clie ntID%>";
    function checkDate(sende r,args){
    cbDay=document. getElementById( client+'_day');
    cbMonth=documen t.getElementByI d(client+'_mont h');
    cbYear=document .getElementById (client+'_year' );
    document.getEle mentById(client +'_err_msg').in nerHTML="";
    if
    (cbDay.selected Index>0&&cbMont h.selectedIndex >0&&cbYear.sele ctedIndex>0)
    args.IsValid=tr ue;
    else
    {
    if
    (cbDay.selected Index==0&&cbMon th.selectedInde x==0&&cbYear.se lectedIndex==0)
    args.IsValid=tr ue;
    else
    {
    args.IsValid=fa lse;
    document.getEle mentById(client +'_err_msg').in nerHTML="Invali d
    date";
    }
    }
    }

    And more code to check if the date is correct if the user selects a month
    that contains 30 or 31 days and adjust the number of days if the month is
    february.
    This function is called on an event that I add on the codebehind the month
    and year dropdownlists like

    month.attribute["onchange"]=setDate('"+day .ClientID+"','" +month.ClientID +"','"+year.Cli entID+"')";
    year.attribute["onchange"]=setDate('"+day .ClientID+"','" +month.ClientID +"','"+year.Cli entID+"')";



    On the aspx page, I have

    <asp:dropDownli st runat="server" id="day" />
    <asp:dropDownli st runat="server" id="month" />
    <asp:dropDownli st runat="server" id="year" />



    The codebehind binds the initial values for the dropdownlists.

    My first idea was to set a customvalidator onto one dropdownlist
    <asp:CustomVali dator ruen="server" id="cvDate" ControlToValida te="day"
    ClientValidatio nFunction="chec kDate"
    Display="non" ValidationGroup e="date" />
    But it doesn't work, I get the "invalid date" if I change the day (of course
    because the 2 other dropdownlists are blank).

    How can I create the good customvalidator ?

    Thanks for your help
    Stan






  • Hans Kesting

    #2
    Re: CustomValidator

    Hi,
    >
    I have a web user control that contains 3 dropdownlists
    it's a date selector, so one contains the days, one the months and the
    last
    the years.
    Each of them starts with a blank value.
    I want to control if the date is valid or blank (that means all the
    dropdownlist have a blank value).
    >
    I need to add a customvalidator but I don't know on which control I
    have to set it.
    >
    For a CustomValidator , you are allowed to leave "ControlToValid ate" blank.

    Hans Kesting


    Comment

    • Stan SR

      #3
      Re: CustomValidator

      Many thanks Hans, it works.
      But I have another question about the same user control.
      I ve put 2 of the same user controls onto a webform.

      On this webform, I put a button with a validationgroup attribute.

      On the customvalidator (of the user control) I set ValidationGroup with the
      same value of the webform validationgroup .

      When I submit my webform,
      it seems the customvalidator of the 2nd usercontrol is checked.

      Do I miss something on the user control ?
      I m not sure that I have to set a validationgroup on the webform.

      Stan





      "Hans Kesting" <news.2.hansdk@ spamgourmet.com a écrit dans le message de
      news:c04e80a710 e738c95f8c684f4 685@news.micros oft.com...
      >Hi,
      >>
      >I have a web user control that contains 3 dropdownlists
      >it's a date selector, so one contains the days, one the months and the
      >last
      >the years.
      >Each of them starts with a blank value.
      >I want to control if the date is valid or blank (that means all the
      >dropdownlist have a blank value).
      >>
      >I need to add a customvalidator but I don't know on which control I
      >have to set it.
      >>
      >
      For a CustomValidator , you are allowed to leave "ControlToValid ate" blank.
      >
      Hans Kesting
      >
      >

      Comment

      • Stan SR

        #4
        Re: CustomValidator

        Ok, I ve found the issue...
        Many thanks Hans, it works.
        But I have another question about the same user control.
        I ve put 2 of the same user controls onto a webform.
        >
        On this webform, I put a button with a validationgroup attribute.
        >
        On the customvalidator (of the user control) I set ValidationGroup with
        the same value of the webform validationgroup .
        >
        When I submit my webform,
        it seems the customvalidator of the 2nd usercontrol is checked.
        >
        Do I miss something on the user control ?
        I m not sure that I have to set a validationgroup on the webform.
        >
        Stan
        >
        >
        >
        >
        >
        "Hans Kesting" <news.2.hansdk@ spamgourmet.com a écrit dans le message de
        news:c04e80a710 e738c95f8c684f4 685@news.micros oft.com...
        >>Hi,
        >>>
        >>I have a web user control that contains 3 dropdownlists
        >>it's a date selector, so one contains the days, one the months and the
        >>last
        >>the years.
        >>Each of them starts with a blank value.
        >>I want to control if the date is valid or blank (that means all the
        >>dropdownlis t have a blank value).
        >>>
        >>I need to add a customvalidator but I don't know on which control I
        >>have to set it.
        >>>
        >>
        >For a CustomValidator , you are allowed to leave "ControlToValid ate"
        >blank.
        >>
        >Hans Kesting
        >>
        >>
        >

        Comment

        Working...