Go Back   Cyber Tech Help Support Forums > Software > Web Development & Graphic Design

Notices

Reply
 
Topic Tools
  #1  
Old October 23rd, 2003, 04:05 PM
gicio gicio is offline
Member
 
Join Date: Aug 2003
Posts: 59
Question ASP.NET: Problems with CustomValidator...

Hi!

I have a litte problem with my CustomValidator.


What my CustomValidator should do:
The CustomValidator should check if 2 textboxes are empty..
if yes he should diplay a message.


This is my code:

Code:
<asp:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie müssen min. 1 Telefonnummer angeben"
		Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P>

Code:
	<script runat="server">
		void ValidateExistanceOfPhones(object source, ServerValidateEventArgs args)
		{
			args.IsValid = !((m_txtTelephoneNumber.Text.Length == 0) && (m_txtMobileNumber.Text.Length == 0));
		}
	</script>


the calidator check ValidateExistanceOfPhones. but when args.IsValid = false the message isn't
shown. What is the problem??!
Make I something wrong?

2. quastion: is it possible to check the state of the 2 textboxes on the client side?
when YES how?



best regards,


gicio
Reply With Quote
  #2  
Old October 23rd, 2003, 08:33 PM
Steven.Bentley Steven.Bentley is offline
CTH Subscriber
 
Join Date: Nov 2000
Location: West Yorkshire, UK
Age: 29
Posts: 3,840
I have no experience of ASP, however it's definitely possible to use JavaScript to validate this on the client side.

Code:
<script>
function validate(){
score=0
if(document.myform.text1.value=""){
message="text1 has not been filled in"
score++
}
if(document.myform.text2.value=""){
score++
message="text2 has not been filled in"
}

if(score==0){
document.myform.submit()
}else{
alert(message);
}
}
</script>


<form action="yourscript.asp" name="myform">

<input type="text" name="text1" />
<input type="text" name="text2" />

<input type="button" onclick="validate()" value="Go">

</form>
The function validate() is called when the button (a regular button rather than submit) is clicked. The function starts by initialising a variable score to 0, then checks each of the inputs seperately and incremements score if the test is "failed", putting a message into the variable message. Then it checks score and either submits the form or pops up an alert containing message as appropriate.
__________________
Don't forget to post back with the results
Reply With Quote
Reply

Bookmarks

Topic 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
Forum Jump


All times are GMT +1. The time now is 02:50 AM.

[ RSS ]