Javascript question on customvalidation

Discussion in 'ASP .Net' started by gane kol, Apr 14, 2005.

  1. gane kol

    gane kol Guest

    Hi

    I have a set of Yes/No radio buttons with textboxes for each. I need to
    write a common customvalidation function that checks, if radiobutton "yes"
    is selected, the value in the corresponding textbox should be greater than
    0.

    For eg:
    IsVM Qty: <radX0Yes> YES <radX0No> NO Qty: <txt00>
    IsVM1 Qty: <radX1Yes> YES <radX1Yes> NO Qty: <txt11>
    IsVM2 Qty: <radX2Yes> YES <radX2Yes> NO Qty: <txt22>
    IsVM3 Qty: <radX3Yes> YES <radX3Yes> NO Qty: <txt33>

    I created a customvalidator with clientsidevalidation for each set.
    <asp:CustomValidator id="cvVM" runat="server" ErrorMessage="Required"
    ControlToValidate="txtVMQty"
    ClientValidationFunction="ValidateQty('radX0Yes','txt00')"></asp:CustomValid
    ator>

    function ValidateQty(objRadId,objTxtBoxId){

    if (document.getElementById(objRadId).checked){

    if (document.getElementById(objTxtBoxId).value <= 0){

    arguments.IsValid = false; ??????

    }}}

    How can i make the arguments.IsValid to false or true based on the
    condition?

    Thanks
    Gane
    gane kol, Apr 14, 2005
    #1
    1. Advertising

  2. gane kol

    Brock Allen Guest

    It should be just this: ClientValidationFunction="ValidateQty"

    And the signature of the method should take 2 arguments, the first is the
    validation tag and the seconds is the args to say if valdation passed or not:

    function ValidateQty(sender, args){
    if (document.getElementById(sender.controltovalidate).checked){
    if (document.getElementById(sender.controltovalidate).value <= 0){

    args.IsValid = false;

    }}}

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi
    >
    > I have a set of Yes/No radio buttons with textboxes for each. I need
    > to write a common customvalidation function that checks, if
    > radiobutton "yes" is selected, the value in the corresponding textbox
    > should be greater than 0.
    >
    > For eg:
    > IsVM Qty: <radX0Yes> YES <radX0No> NO Qty: <txt00>
    > IsVM1 Qty: <radX1Yes> YES <radX1Yes> NO Qty: <txt11>
    > IsVM2 Qty: <radX2Yes> YES <radX2Yes> NO Qty: <txt22>
    > IsVM3 Qty: <radX3Yes> YES <radX3Yes> NO Qty: <txt33>
    > I created a customvalidator with clientsidevalidation for each set.
    > <asp:CustomValidator id="cvVM" runat="server" ErrorMessage="Required"
    > ControlToValidate="txtVMQty"
    > ClientValidationFunction="ValidateQty('radX0Yes','txt00')"></asp:Custo
    > mValid
    >
    > function ValidateQty(objRadId,objTxtBoxId){
    >
    > if (document.getElementById(objRadId).checked){
    >
    > if (document.getElementById(objTxtBoxId).value <= 0){
    >
    > arguments.IsValid = false; ??????
    >
    > }}}
    >
    > How can i make the arguments.IsValid to false or true based on the
    > condition?
    >
    > Thanks
    > Gane
    Brock Allen, Apr 14, 2005
    #2
    1. Advertising

  3. gane kol

    gane kol Guest

    i am trying to write a general function.
    I need to pass the webcontrol ids as paramater to the function as well.

    the code looks like and i have similar codeblocks like below
    ---------
    <asp:radiobutton id="radVMYes" runat="server" CssClass="radbtn" Text="Yes"
    GroupName="radVM"></asp:radiobutton>
    <asp:radiobutton id="radVMNo" runat="server" CssClass="radbtn" Text="No"
    GroupName="radVM" Checked = "true"></asp:radiobutton>
    &nbsp;&nbsp;Qty:&nbsp;<asp:textbox id="txtVMQty" runat="server" Columns="2"
    cssclass="txtinput" enabled = "false">0</asp:textbox>
    <asp:CustomValidator id="cvVMail" runat="server" ErrorMessage="Required"
    ControlToValidate="txtVMQty"
    ClientValidationFunction="ValidateQty"></asp:CustomValidator>
    ----------



    "Brock Allen" <> wrote in message
    news:...
    > It should be just this: ClientValidationFunction="ValidateQty"
    >
    > And the signature of the method should take 2 arguments, the first is the
    > validation tag and the seconds is the args to say if valdation passed or

    not:
    >
    > function ValidateQty(sender, args){
    > if (document.getElementById(sender.controltovalidate).checked){
    > if (document.getElementById(sender.controltovalidate).value <= 0){
    >
    > args.IsValid = false;
    >
    > }}}
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hi
    > >
    > > I have a set of Yes/No radio buttons with textboxes for each. I need
    > > to write a common customvalidation function that checks, if
    > > radiobutton "yes" is selected, the value in the corresponding textbox
    > > should be greater than 0.
    > >
    > > For eg:
    > > IsVM Qty: <radX0Yes> YES <radX0No> NO Qty: <txt00>
    > > IsVM1 Qty: <radX1Yes> YES <radX1Yes> NO Qty: <txt11>
    > > IsVM2 Qty: <radX2Yes> YES <radX2Yes> NO Qty: <txt22>
    > > IsVM3 Qty: <radX3Yes> YES <radX3Yes> NO Qty: <txt33>
    > > I created a customvalidator with clientsidevalidation for each set.
    > > <asp:CustomValidator id="cvVM" runat="server" ErrorMessage="Required"
    > > ControlToValidate="txtVMQty"
    > > ClientValidationFunction="ValidateQty('radX0Yes','txt00')"></asp:Custo
    > > mValid
    > >
    > > function ValidateQty(objRadId,objTxtBoxId){
    > >
    > > if (document.getElementById(objRadId).checked){
    > >
    > > if (document.getElementById(objTxtBoxId).value <= 0){
    > >
    > > arguments.IsValid = false; ??????
    > >
    > > }}}
    > >
    > > How can i make the arguments.IsValid to false or true based on the
    > > condition?
    > >
    > > Thanks
    > > Gane

    >
    >
    >
    gane kol, Apr 14, 2005
    #3
  4. You could place them as an attribute on your validator.

    <asp:CustomValidator
    id="cvVMail"
    runat="server"
    ErrorMessage="Required"
    ClientValidationFunction="ValidateQty"
    cbControl="radVMYes"
    txtControl="txtVMQty"
    />

    Notice I removed the ControlToValidate property.

    Your custom validation will now look something like this.

    function ValidateQty( object, args )
    {
    if ( document.all[object.cbControl].checked == true ) {
    if ( document.all[object.txtControl].value == "" )
    args.isValid = false;
    }

    args.isValid = true;
    }



    "gane kol" <> wrote in message
    news:%...
    > i am trying to write a general function.
    > I need to pass the webcontrol ids as paramater to the function as well.
    >
    > the code looks like and i have similar codeblocks like below
    > ---------
    > <asp:radiobutton id="radVMYes" runat="server" CssClass="radbtn" Text="Yes"
    > GroupName="radVM"></asp:radiobutton>
    > <asp:radiobutton id="radVMNo" runat="server" CssClass="radbtn" Text="No"
    > GroupName="radVM" Checked = "true"></asp:radiobutton>
    > &nbsp;&nbsp;Qty:&nbsp;<asp:textbox id="txtVMQty" runat="server"

    Columns="2"
    > cssclass="txtinput" enabled = "false">0</asp:textbox>
    > <asp:CustomValidator id="cvVMail" runat="server" ErrorMessage="Required"
    > ControlToValidate="txtVMQty"
    > ClientValidationFunction="ValidateQty"></asp:CustomValidator>
    > ----------
    >
    >
    >
    > "Brock Allen" <> wrote in message
    > news:...
    > > It should be just this: ClientValidationFunction="ValidateQty"
    > >
    > > And the signature of the method should take 2 arguments, the first is

    the
    > > validation tag and the seconds is the args to say if valdation passed or

    > not:
    > >
    > > function ValidateQty(sender, args){
    > > if (document.getElementById(sender.controltovalidate).checked){
    > > if (document.getElementById(sender.controltovalidate).value <= 0){
    > >
    > > args.IsValid = false;
    > >
    > > }}}
    > >
    > > -Brock
    > > DevelopMentor
    > > http://staff.develop.com/ballen
    > >
    > >
    > >
    > > > Hi
    > > >
    > > > I have a set of Yes/No radio buttons with textboxes for each. I need
    > > > to write a common customvalidation function that checks, if
    > > > radiobutton "yes" is selected, the value in the corresponding textbox
    > > > should be greater than 0.
    > > >
    > > > For eg:
    > > > IsVM Qty: <radX0Yes> YES <radX0No> NO Qty: <txt00>
    > > > IsVM1 Qty: <radX1Yes> YES <radX1Yes> NO Qty: <txt11>
    > > > IsVM2 Qty: <radX2Yes> YES <radX2Yes> NO Qty: <txt22>
    > > > IsVM3 Qty: <radX3Yes> YES <radX3Yes> NO Qty: <txt33>
    > > > I created a customvalidator with clientsidevalidation for each set.
    > > > <asp:CustomValidator id="cvVM" runat="server" ErrorMessage="Required"
    > > > ControlToValidate="txtVMQty"
    > > > ClientValidationFunction="ValidateQty('radX0Yes','txt00')"></asp:Custo
    > > > mValid
    > > >
    > > > function ValidateQty(objRadId,objTxtBoxId){
    > > >
    > > > if (document.getElementById(objRadId).checked){
    > > >
    > > > if (document.getElementById(objTxtBoxId).value <= 0){
    > > >
    > > > arguments.IsValid = false; ??????
    > > >
    > > > }}}
    > > >
    > > > How can i make the arguments.IsValid to false or true based on the
    > > > condition?
    > > >
    > > > Thanks
    > > > Gane

    > >
    > >
    > >

    >
    >
    William F. Robertson, Jr., Apr 15, 2005
    #4
    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. =?Utf-8?B?cm9kY2hhcg==?=

    datagrid template columns and customvalidation

    =?Utf-8?B?cm9kY2hhcg==?=, Oct 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    415
    =?Utf-8?B?RmVybmFuZG8gSHVudGg=?=
    Jan 11, 2005
  2. kpg
    Replies:
    2
    Views:
    740
    Peter Blum
    Dec 22, 2004
  3. Craig Buchanan
    Replies:
    1
    Views:
    359
    Peter Bucher [MVP]
    Sep 10, 2008
  4. Craig Buchanan

    Web User Control with CustomValidation and Javascript

    Craig Buchanan, Aug 18, 2008, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    744
    Peter Bucher [MVP]
    Sep 10, 2008
  5. Craig Buchanan

    Web User Control with CustomValidation and Javascript

    Craig Buchanan, Aug 18, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    139
    Peter Bucher [MVP]
    Sep 10, 2008
Loading...

Share This Page