Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2004, 01:12 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have specified my validation condition when I started my thread. All I need is that out of 2 textboxes, one and only one should be entered. I can't figure out how to use custom validators. Can anybody help me do this.

Thanks!

 
Old December 13th, 2004, 02:26 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

sorry I didnt pay attention to your firs post,if your condition is just that you wont need to use CustomValidators,use two Requiredfieldvalidators for two TextBoxes and set their
EnableClienScript to false,then in Button_Click event check their IsValid property like below,
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
 Handles Button1.Click
        Dim msg As String
        'Checks every IsValid property
        If (RequiredFieldValidator1.IsValid and Not RequiredFieldValidator2.IsValid or
              Not RequiredFieldValidator1.IsValid and RequiredFieldValidator2.IsValid ) Then
            msg = "good"
        Else
            msg = "bad"
        End If
End Sub
I hope this helps,
(sorry for my english).

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 13th, 2004, 03:22 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mehdi-
This is exactly what I posted in my 4th post for this thread. The problem is how do I show the error message in the validation summary instead of moving a value to a variable. The condition below in the Button_Click even is the condition when it should raise and error. Even when I set EnableClientScript to false, it still fires it.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If RequiredFieldValidator1.IsValid = RequiredFieldValidator2.IsValid Then

            ' Then I need to show the error in validation summarybox. How do I do that?
        End If
    End Sub

I hope I have clarified the problem.


 
Old December 13th, 2004, 04:44 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

for showing your result,put <asp:ValidationSummary/> tag where you want to show the result in your page,
Code:
<asp:ValidationSummary
  HeaderText="There are problems with the following
    form fields:"
  Runat="Server" />
if you want to show it in a popup window,you cant because you are validating them in sever-side,
if you insist on validating your field in server-side I think you cant show them in a popup window,
(IMO you can show them somewhere in your page cleaner rather than showing within a popup window,I dont know-
exactly why you try to validate them in server-side,do you think it costs at all!?)
_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 14th, 2004, 09:56 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you suggest me a way of doing it on Client side. I think I will have to use Javascript. I don't know Javascript, but I guess I can figure it out. Using JavaScript can it be shown in the pop up window? I guess it can be using window.open. Am I write?

 
Old December 14th, 2004, 02:34 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think here it's better to use CustomValidator,it has a property for client-side validations,
I mean ClientValidationFunction,then write a javascript function for checking-
your texboxes and set that property to your javascript function,then ValidationSummary can show
error messages in a po pup window,I'm not familiar with javascript's tricks(ask them in javascript forum),
Regards.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 14th, 2004, 04:50 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ah,no,I again returned to my first place,dont use CustomValidator it cant
validate empety TextBoxes(even on client-side)IMO use server-side validations,but ignore
po pup window.(if I were you I would do it,in my opinion it's a cleaner job).

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 16th, 2004, 01:56 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Renu,
Thanks for your reply on my post.
My solution seemed to work but i still think it is not ideal.

Basically what I did is add another textbox with its display set to none so it can't be seen.
Ensure that it has a value.
I set mine to "This is needed to fire the custom validator script".
Set that textbox as the "ControlToValidate".
As you know the textbox has a value the "ClientValidationFunction" will always fire.

Then just use javascript to validate instead of args.value.
ie document.all.textbox1.value

so you might say
Code:
if((document.all.textbox1.value > 5) && (document.all.textbox2.value <7))
(
 args.IsValid = true;
)
else
(
args.IsValid = false;

)
Basically the trick is to force the event to fire by pointing it to a textbox that will always have a value, then ignoring the args.value.

Id still be interested in finding a better way.

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old December 16th, 2004, 09:58 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Renu,I think I found the solution,you can do it like below...(on the client-side)
Code:
private void Page_Load(object sender, System.EventArgs e)
{
    string s="";
    s+="var txtbox1=document.getElementById('TextBox1');var txtbox2=document.getElementById('TextBox2');";
    s+="if (txtbox1.value=='' && txtbox2.value=='' || txtbox1.value!='' && txtbox2.value!=''){window.alert('Validation not acceptable.');return false;}";
    yourValidationButton.Attributes.Add("onclick", s);
}
_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old December 16th, 2004, 03:48 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mehdi-
but I know very little javascript. I tried to put it in the HEAD section between the <script> tags. Do I need to add anything else. though it is declared void, but seems to be returning a value. i am a bit confused. Please reply as I think that this will be the solution.
Thanks a lot!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation controls and postback sdi126 ASP.NET 2.0 Basics 5 November 11th, 2007 12:08 PM
User controls and validation relaytest49 ASP.NET 2.0 Professional 1 October 11th, 2006 01:25 PM
Validation Controls andyj00 ASP.NET 1.0 and 1.1 Professional 3 June 9th, 2005 09:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.