Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Need help on validation on a group of controls

Reply
Thread Tools

Need help on validation on a group of controls

 
 
Learner
Guest
Posts: n/a
 
      06-08-2006
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

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      06-09-2006
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==
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.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

"Learner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
 
Learner
Guest
Posts: n/a
 
      06-13-2006
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==
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==
> 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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "Learner" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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
> >


 
Reply With Quote
 
Nathan Sokalski
Guest
Posts: n/a
 
      06-14-2006
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==
{
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
(E-Mail Removed)
http://www.nathansokalski.com/

"Learner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
> 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==
> 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==
>> 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
>> (E-Mail Removed)
>> http://www.nathansokalski.com/
>>
>> "Learner" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) oups.com...
>> > 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
>> >

>



 
Reply With Quote
 
Learner
Guest
Posts: n/a
 
      06-14-2006
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==
> {
> 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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "Learner" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ps.com...
> > 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==
> > 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==
> >> 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
> >> (E-Mail Removed)
> >> http://www.nathansokalski.com/
> >>
> >> "Learner" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed) oups.com...
> >> > 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
> >> >

> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the validation occurs for validation controls baroque Chou ASP .Net 4 01-24-2006 03:32 PM
Page appears to fail validation even though it has no validation controls =?Utf-8?B?ZGh1cndpdHo=?= ASP .Net 1 04-10-2004 07:37 AM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
how to group validation controls and enable/disable them buran ASP .Net 0 09-26-2003 12:51 PM
how to group validation controls and enable/disable them buran ASP .Net Web Controls 0 09-26-2003 12:51 PM



Advertisments