Need help on validation on a group of controls

Discussion in 'ASP .Net Web Controls' started by Learner, Jun 8, 2006.

  1. Learner

    Learner Guest

    Hi Friends,
    I have two things that I am running short of ideas on how to solve.
    I am working on medium sized search form where in I will have to do
    considerable validations befor it submits the form.

    1).I have to put a validation on a text box ( _txtVIN ) such that it
    min and max charecters should be 8. In other words user shouldn't be
    able to enter more than 8 charecters of the total VIN numner. At the
    same user must enter 8 charecters if at all he eneters some thing in
    the text field. I have put the max length property to put a cap on the
    number of charectors entered. But no clue how do I do it in the case
    min of 8 charecters?

    2). I have 3 text boxes. I need to make sure that atleast one filed has
    the text in it before it submits the form. In other words user must
    enter atleast a value in any of the text boxes. I am not sure what
    control would do best to do this?

    say _txtYear, _txtMake, _txtModel and the form shoudln't submit unless
    user provides atleast a value in the respective fileds.


    Any inputs is greatly appreciated,
    Thanks,
    -L
    Learner, Jun 8, 2006
    #1
    1. Advertising

  2. My suggestion for both of these problems would be to use the CustomValidator
    control. For your first problem, I would use the following as your
    server-side event and the CustomValidator's ClientValidationFunction
    property:

    Sub val8Chars_ServerValidate(source As Object, args As
    ServerValidateEventArgs) Handles val8Chars.ServerValidate
    If txtMyTextBox.Text.Length = 8 Then args.IsValid = True Else args.IsValid
    = False
    End Sub

    <script type="text/javascript">
    function val8Chars_ServerValidate(source,args)
    {
    if(args.value.length==8)
    args.IsValid=true;
    else
    args.IsValid=false;
    }
    </script>


    For your second problem, I would use the following server-side event:

    Sub valMustPickOne_ServerValidate(source As Object, args As
    ServerValidateEventArgs) Handles valMustPickOne.ServerValidate
    If txtMyTextBox1.Text = "" AndAlso txtMyTextBox2.Text = "" AndAlso
    txtMyTextBox3.Text = "" Then args.IsValid = False Else args.IsValid = True
    End Sub

    If you wanted to make a ClientValidationFunction function for this, I would
    suggest generating it dynamically using the ClientID property of the three
    controls and adding the script using the RegisterClientScriptBlock method
    because the validation involves the value of multiple controls. for more
    information on how to do this, see the ASP.NET documentation and JavaScript
    documentation. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Learner" <> wrote in message
    news:...
    > Hi Friends,
    > I have two things that I am running short of ideas on how to solve.
    > I am working on medium sized search form where in I will have to do
    > considerable validations befor it submits the form.
    >
    > 1).I have to put a validation on a text box ( _txtVIN ) such that it
    > min and max charecters should be 8. In other words user shouldn't be
    > able to enter more than 8 charecters of the total VIN numner. At the
    > same user must enter 8 charecters if at all he eneters some thing in
    > the text field. I have put the max length property to put a cap on the
    > number of charectors entered. But no clue how do I do it in the case
    > min of 8 charecters?
    >
    > 2). I have 3 text boxes. I need to make sure that atleast one filed has
    > the text in it before it submits the form. In other words user must
    > enter atleast a value in any of the text boxes. I am not sure what
    > control would do best to do this?
    >
    > say _txtYear, _txtMake, _txtModel and the form shoudln't submit unless
    > user provides atleast a value in the respective fileds.
    >
    >
    > Any inputs is greatly appreciated,
    > Thanks,
    > -L
    >
    Nathan Sokalski, Jun 9, 2006
    #2
    1. Advertising

  3. Learner

    Learner Guest

    Hello Nathan,
    I appriciate your response on this and the same time I am admit that
    its been delayed in responding to this posting as I have been occupied
    with other stuff. I am sorry about that.

    Now, the server side event handling worked good for my _txtVIN text
    box. here is the code

    **************************************************************************
    Protected Sub _CustvldVIN_ServerValidate(ByVal source As Object, ByVal
    args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
    _CustvldVIN.ServerValidate
    If _txtVIN.Text.Length = 8 Then
    args.IsValid = True
    Else
    args.IsValid = False
    _CustvldVIN.Text = "Please enter CUST valid VIN"
    End If
    End Sub
    *************************************************************************
    and I put the
    If page.isValid then
    End if
    code in the _btn_search_click event and it returns false if length is
    less than 8.


    But when I try doing it using Javascript it validates the txt entere
    the _txtVIN text box but it generates a java script error on the left
    bottom of the browser
    it says "Object expected" when I double clicked on the error. I am not
    sure if this some thing to do with Internet explorer IE 7.0 (beta
    version) I am using.

    Here is the defenition of the CustomValidator control in my .aspx page
    **********************************************************************************************
    <asp:CustomValidator ID="_CustvldVIN" runat="server"
    ControlToValidate="_txtVIN"
    ErrorMessage="Please enter Cusvld VIN!"


    OnServerValidate="_CustvldVIN_ServerValidate"
    ClientValidationFunction="TestVIN">
    </asp:CustomValidator>
    **********************************************************************************************

    and the java script function that I have in my common.js script file is


    ****************************************************************************************************
    function TestVin(source,args)
    {
    if(args.value.length==8)
    args.IsValid=true;
    else
    args.IsValid=false;
    }
    ****************************************************************************************************


    Am I missing some thing here?

    Please advice,
    Thanks
    -L



    Nathan Sokalski wrote:
    > My suggestion for both of these problems would be to use the CustomValidator
    > control. For your first problem, I would use the following as your
    > server-side event and the CustomValidator's ClientValidationFunction
    > property:
    >
    > Sub val8Chars_ServerValidate(source As Object, args As
    > ServerValidateEventArgs) Handles val8Chars.ServerValidate
    > If txtMyTextBox.Text.Length = 8 Then args.IsValid = True Else args.IsValid
    > = False
    > End Sub
    >
    > <script type="text/javascript">
    > function val8Chars_ServerValidate(source,args)
    > {
    > if(args.value.length==8)
    > args.IsValid=true;
    > else
    > args.IsValid=false;
    > }
    > </script>
    >
    >
    > For your second problem, I would use the following server-side event:
    >
    > Sub valMustPickOne_ServerValidate(source As Object, args As
    > ServerValidateEventArgs) Handles valMustPickOne.ServerValidate
    > If txtMyTextBox1.Text = "" AndAlso txtMyTextBox2.Text = "" AndAlso
    > txtMyTextBox3.Text = "" Then args.IsValid = False Else args.IsValid = True
    > End Sub
    >
    > If you wanted to make a ClientValidationFunction function for this, I would
    > suggest generating it dynamically using the ClientID property of the three
    > controls and adding the script using the RegisterClientScriptBlock method
    > because the validation involves the value of multiple controls. for more
    > information on how to do this, see the ASP.NET documentation and JavaScript
    > documentation. Good Luck!
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Learner" <> wrote in message
    > news:...
    > > Hi Friends,
    > > I have two things that I am running short of ideas on how to solve.
    > > I am working on medium sized search form where in I will have to do
    > > considerable validations befor it submits the form.
    > >
    > > 1).I have to put a validation on a text box ( _txtVIN ) such that it
    > > min and max charecters should be 8. In other words user shouldn't be
    > > able to enter more than 8 charecters of the total VIN numner. At the
    > > same user must enter 8 charecters if at all he eneters some thing in
    > > the text field. I have put the max length property to put a cap on the
    > > number of charectors entered. But no clue how do I do it in the case
    > > min of 8 charecters?
    > >
    > > 2). I have 3 text boxes. I need to make sure that atleast one filed has
    > > the text in it before it submits the form. In other words user must
    > > enter atleast a value in any of the text boxes. I am not sure what
    > > control would do best to do this?
    > >
    > > say _txtYear, _txtMake, _txtModel and the form shoudln't submit unless
    > > user provides atleast a value in the respective fileds.
    > >
    > >
    > > Any inputs is greatly appreciated,
    > > Thanks,
    > > -L
    > >
    Learner, Jun 13, 2006
    #3
  4. I'm not sure what is wrong. It could have something to do with IE7, I
    haven't tried the Beta version. One other thing that could be the problem
    (different browsers are pickier than others, and who knows what IE7 wants)
    is the JavaScript syntax. Try changing the JavaScript syntax to the
    following and see if it makes a difference:

    function TestVin(source,args)
    {
    if(args.value.length==8)
    {
    args.IsValid=true;
    }
    else
    {
    args.IsValid=false;
    }
    }

    Even though this is the same algorithm, maybe IE7 requires the {} around the
    code inside the if/else statement. Something else that you could try is
    writing a small little html page to test the JavaScript function to see if
    the function is really the problem. I will also admit that, even though I
    have used them once or twice and am working on learning more about them, I
    do not have the huge amount of experience with client-side validation being
    used with the ASP.NET Validators, but as always, we come here to help each
    other with what we know, and possibly learn more in the process, so I'll do
    what I can! Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Learner" <> wrote in message
    news:...
    > Hello Nathan,
    > I appriciate your response on this and the same time I am admit that
    > its been delayed in responding to this posting as I have been occupied
    > with other stuff. I am sorry about that.
    >
    > Now, the server side event handling worked good for my _txtVIN text
    > box. here is the code
    >
    > **************************************************************************
    > Protected Sub _CustvldVIN_ServerValidate(ByVal source As Object, ByVal
    > args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
    > _CustvldVIN.ServerValidate
    > If _txtVIN.Text.Length = 8 Then
    > args.IsValid = True
    > Else
    > args.IsValid = False
    > _CustvldVIN.Text = "Please enter CUST valid VIN"
    > End If
    > End Sub
    > *************************************************************************
    > and I put the
    > If page.isValid then
    > End if
    > code in the _btn_search_click event and it returns false if length is
    > less than 8.
    >
    >
    > But when I try doing it using Javascript it validates the txt entere
    > the _txtVIN text box but it generates a java script error on the left
    > bottom of the browser
    > it says "Object expected" when I double clicked on the error. I am not
    > sure if this some thing to do with Internet explorer IE 7.0 (beta
    > version) I am using.
    >
    > Here is the defenition of the CustomValidator control in my .aspx page
    > **********************************************************************************************
    > <asp:CustomValidator ID="_CustvldVIN" runat="server"
    > ControlToValidate="_txtVIN"
    > ErrorMessage="Please enter Cusvld VIN!"
    >
    >
    > OnServerValidate="_CustvldVIN_ServerValidate"
    > ClientValidationFunction="TestVIN">
    > </asp:CustomValidator>
    > **********************************************************************************************
    >
    > and the java script function that I have in my common.js script file is
    >
    >
    > ****************************************************************************************************
    > function TestVin(source,args)
    > {
    > if(args.value.length==8)
    > args.IsValid=true;
    > else
    > args.IsValid=false;
    > }
    > ****************************************************************************************************
    >
    >
    > Am I missing some thing here?
    >
    > Please advice,
    > Thanks
    > -L
    >
    >
    >
    > Nathan Sokalski wrote:
    >> My suggestion for both of these problems would be to use the
    >> CustomValidator
    >> control. For your first problem, I would use the following as your
    >> server-side event and the CustomValidator's ClientValidationFunction
    >> property:
    >>
    >> Sub val8Chars_ServerValidate(source As Object, args As
    >> ServerValidateEventArgs) Handles val8Chars.ServerValidate
    >> If txtMyTextBox.Text.Length = 8 Then args.IsValid = True Else
    >> args.IsValid
    >> = False
    >> End Sub
    >>
    >> <script type="text/javascript">
    >> function val8Chars_ServerValidate(source,args)
    >> {
    >> if(args.value.length==8)
    >> args.IsValid=true;
    >> else
    >> args.IsValid=false;
    >> }
    >> </script>
    >>
    >>
    >> For your second problem, I would use the following server-side event:
    >>
    >> Sub valMustPickOne_ServerValidate(source As Object, args As
    >> ServerValidateEventArgs) Handles valMustPickOne.ServerValidate
    >> If txtMyTextBox1.Text = "" AndAlso txtMyTextBox2.Text = "" AndAlso
    >> txtMyTextBox3.Text = "" Then args.IsValid = False Else args.IsValid =
    >> True
    >> End Sub
    >>
    >> If you wanted to make a ClientValidationFunction function for this, I
    >> would
    >> suggest generating it dynamically using the ClientID property of the
    >> three
    >> controls and adding the script using the RegisterClientScriptBlock method
    >> because the validation involves the value of multiple controls. for more
    >> information on how to do this, see the ASP.NET documentation and
    >> JavaScript
    >> documentation. Good Luck!
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >> "Learner" <> wrote in message
    >> news:...
    >> > Hi Friends,
    >> > I have two things that I am running short of ideas on how to solve.
    >> > I am working on medium sized search form where in I will have to do
    >> > considerable validations befor it submits the form.
    >> >
    >> > 1).I have to put a validation on a text box ( _txtVIN ) such that it
    >> > min and max charecters should be 8. In other words user shouldn't be
    >> > able to enter more than 8 charecters of the total VIN numner. At the
    >> > same user must enter 8 charecters if at all he eneters some thing in
    >> > the text field. I have put the max length property to put a cap on the
    >> > number of charectors entered. But no clue how do I do it in the case
    >> > min of 8 charecters?
    >> >
    >> > 2). I have 3 text boxes. I need to make sure that atleast one filed has
    >> > the text in it before it submits the form. In other words user must
    >> > enter atleast a value in any of the text boxes. I am not sure what
    >> > control would do best to do this?
    >> >
    >> > say _txtYear, _txtMake, _txtModel and the form shoudln't submit unless
    >> > user provides atleast a value in the respective fileds.
    >> >
    >> >
    >> > Any inputs is greatly appreciated,
    >> > Thanks,
    >> > -L
    >> >

    >
    Nathan Sokalski, Jun 14, 2006
    #4
  5. Learner

    Learner Guest

    Hello Nathan,
    Thanks buddy. Yes you are right its all about playing with the new
    technolog and its always fun. Thanks a bunch for your detailed
    explanation. I will let you know if I could figure out and fix the bug
    :)

    Thanks buddy
    -L
    Nathan Sokalski wrote:
    > I'm not sure what is wrong. It could have something to do with IE7, I
    > haven't tried the Beta version. One other thing that could be the problem
    > (different browsers are pickier than others, and who knows what IE7 wants)
    > is the JavaScript syntax. Try changing the JavaScript syntax to the
    > following and see if it makes a difference:
    >
    > function TestVin(source,args)
    > {
    > if(args.value.length==8)
    > {
    > args.IsValid=true;
    > }
    > else
    > {
    > args.IsValid=false;
    > }
    > }
    >
    > Even though this is the same algorithm, maybe IE7 requires the {} around the
    > code inside the if/else statement. Something else that you could try is
    > writing a small little html page to test the JavaScript function to see if
    > the function is really the problem. I will also admit that, even though I
    > have used them once or twice and am working on learning more about them, I
    > do not have the huge amount of experience with client-side validation being
    > used with the ASP.NET Validators, but as always, we come here to help each
    > other with what we know, and possibly learn more in the process, so I'll do
    > what I can! Good Luck!
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Learner" <> wrote in message
    > news:...
    > > Hello Nathan,
    > > I appriciate your response on this and the same time I am admit that
    > > its been delayed in responding to this posting as I have been occupied
    > > with other stuff. I am sorry about that.
    > >
    > > Now, the server side event handling worked good for my _txtVIN text
    > > box. here is the code
    > >
    > > **************************************************************************
    > > Protected Sub _CustvldVIN_ServerValidate(ByVal source As Object, ByVal
    > > args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
    > > _CustvldVIN.ServerValidate
    > > If _txtVIN.Text.Length = 8 Then
    > > args.IsValid = True
    > > Else
    > > args.IsValid = False
    > > _CustvldVIN.Text = "Please enter CUST valid VIN"
    > > End If
    > > End Sub
    > > *************************************************************************
    > > and I put the
    > > If page.isValid then
    > > End if
    > > code in the _btn_search_click event and it returns false if length is
    > > less than 8.
    > >
    > >
    > > But when I try doing it using Javascript it validates the txt entere
    > > the _txtVIN text box but it generates a java script error on the left
    > > bottom of the browser
    > > it says "Object expected" when I double clicked on the error. I am not
    > > sure if this some thing to do with Internet explorer IE 7.0 (beta
    > > version) I am using.
    > >
    > > Here is the defenition of the CustomValidator control in my .aspx page
    > > **********************************************************************************************
    > > <asp:CustomValidator ID="_CustvldVIN" runat="server"
    > > ControlToValidate="_txtVIN"
    > > ErrorMessage="Please enter Cusvld VIN!"
    > >
    > >
    > > OnServerValidate="_CustvldVIN_ServerValidate"
    > > ClientValidationFunction="TestVIN">
    > > </asp:CustomValidator>
    > > **********************************************************************************************
    > >
    > > and the java script function that I have in my common.js script file is
    > >
    > >
    > > ****************************************************************************************************
    > > function TestVin(source,args)
    > > {
    > > if(args.value.length==8)
    > > args.IsValid=true;
    > > else
    > > args.IsValid=false;
    > > }
    > > ****************************************************************************************************
    > >
    > >
    > > Am I missing some thing here?
    > >
    > > Please advice,
    > > Thanks
    > > -L
    > >
    > >
    > >
    > > Nathan Sokalski wrote:
    > >> My suggestion for both of these problems would be to use the
    > >> CustomValidator
    > >> control. For your first problem, I would use the following as your
    > >> server-side event and the CustomValidator's ClientValidationFunction
    > >> property:
    > >>
    > >> Sub val8Chars_ServerValidate(source As Object, args As
    > >> ServerValidateEventArgs) Handles val8Chars.ServerValidate
    > >> If txtMyTextBox.Text.Length = 8 Then args.IsValid = True Else
    > >> args.IsValid
    > >> = False
    > >> End Sub
    > >>
    > >> <script type="text/javascript">
    > >> function val8Chars_ServerValidate(source,args)
    > >> {
    > >> if(args.value.length==8)
    > >> args.IsValid=true;
    > >> else
    > >> args.IsValid=false;
    > >> }
    > >> </script>
    > >>
    > >>
    > >> For your second problem, I would use the following server-side event:
    > >>
    > >> Sub valMustPickOne_ServerValidate(source As Object, args As
    > >> ServerValidateEventArgs) Handles valMustPickOne.ServerValidate
    > >> If txtMyTextBox1.Text = "" AndAlso txtMyTextBox2.Text = "" AndAlso
    > >> txtMyTextBox3.Text = "" Then args.IsValid = False Else args.IsValid =
    > >> True
    > >> End Sub
    > >>
    > >> If you wanted to make a ClientValidationFunction function for this, I
    > >> would
    > >> suggest generating it dynamically using the ClientID property of the
    > >> three
    > >> controls and adding the script using the RegisterClientScriptBlock method
    > >> because the validation involves the value of multiple controls. for more
    > >> information on how to do this, see the ASP.NET documentation and
    > >> JavaScript
    > >> documentation. Good Luck!
    > >> --
    > >> Nathan Sokalski
    > >>
    > >> http://www.nathansokalski.com/
    > >>
    > >> "Learner" <> wrote in message
    > >> news:...
    > >> > Hi Friends,
    > >> > I have two things that I am running short of ideas on how to solve.
    > >> > I am working on medium sized search form where in I will have to do
    > >> > considerable validations befor it submits the form.
    > >> >
    > >> > 1).I have to put a validation on a text box ( _txtVIN ) such that it
    > >> > min and max charecters should be 8. In other words user shouldn't be
    > >> > able to enter more than 8 charecters of the total VIN numner. At the
    > >> > same user must enter 8 charecters if at all he eneters some thing in
    > >> > the text field. I have put the max length property to put a cap on the
    > >> > number of charectors entered. But no clue how do I do it in the case
    > >> > min of 8 charecters?
    > >> >
    > >> > 2). I have 3 text boxes. I need to make sure that atleast one filed has
    > >> > the text in it before it submits the form. In other words user must
    > >> > enter atleast a value in any of the text boxes. I am not sure what
    > >> > control would do best to do this?
    > >> >
    > >> > say _txtYear, _txtMake, _txtModel and the form shoudln't submit unless
    > >> > user provides atleast a value in the respective fileds.
    > >> >
    > >> >
    > >> > Any inputs is greatly appreciated,
    > >> > Thanks,
    > >> > -L
    > >> >

    > >
    Learner, Jun 14, 2006
    #5
    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. buran
    Replies:
    0
    Views:
    491
    buran
    Sep 26, 2003
  2. Matt
    Replies:
    14
    Views:
    4,092
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  3. =?Utf-8?B?ZGh1cndpdHo=?=
    Replies:
    1
    Views:
    454
    Teemu Keiski
    Apr 10, 2004
  4. Lloyd Dupont

    need to have 'validation group'

    Lloyd Dupont, Feb 22, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    5,062
    Lloyd Dupont
    Feb 27, 2006
  5. buran
    Replies:
    0
    Views:
    151
    buran
    Sep 26, 2003
Loading...

Share This Page