473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Question about OnServerValidate

jm
I have this CustomValidator:

<asp:CustomValidator runat="server"
OnServerValidate="ValidateThis"
Display="Dynamic"
ControlToValidate="txtMyTextBox"
ErrorMessage="Not a valid entry"/>

On my server side scripts, I have:

sub ValidateThis(obj as Object, args as _
ServerValidateEventArgs)

if len(args.Value) < 8 then
exit sub <---will this stop the submit from firing?
else
submit() <---what argument
end if

end sub

Sub submit(Source As Object, e As EventArgs)
.... put stuff in a database too long to list
end sub

Okay, what I am trying to do is validate args.value (a textbox) and if
it meets or does not meet the criterion, then either stop everything
or submit to the database.

The problem is that no matter what I put in the ValidateThis sub, the
submit will always work. How do I use the OnServerValidate to stop
the entire page from submitting what's on the form. Also, if it does
pass my criterion, how do I get it too submit. Submit has the two
arguments, but I don't know what they want (got it from somewhere); it
does work. The form works, the database inserts data like I want. I
just need to know how to stop it from submitting based on invalid data
- and I don't want to use JavaScript. I can do that already. I want
to do it in .NET. Thanks for any help.
Nov 17 '05 #1
3 1845
You can't stop the page from submitting using server validate. Server
validate is called when the form has been submitting.

You might want to look at client side validation for this control ALSO, so
form will not be submitted. You will still need to have the server
validation on it because it isn't too difficult (I hear) to bypass client
side validation.

bill
"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have this CustomValidator:

<asp:CustomValidator runat="server"
OnServerValidate="ValidateThis"
Display="Dynamic"
ControlToValidate="txtMyTextBox"
ErrorMessage="Not a valid entry"/>

On my server side scripts, I have:

sub ValidateThis(obj as Object, args as _
ServerValidateEventArgs)

if len(args.Value) < 8 then
exit sub <---will this stop the submit from firing?
else
submit() <---what argument
end if

end sub

Sub submit(Source As Object, e As EventArgs)
... put stuff in a database too long to list
end sub

Okay, what I am trying to do is validate args.value (a textbox) and if
it meets or does not meet the criterion, then either stop everything
or submit to the database.

The problem is that no matter what I put in the ValidateThis sub, the
submit will always work. How do I use the OnServerValidate to stop
the entire page from submitting what's on the form. Also, if it does
pass my criterion, how do I get it too submit. Submit has the two
arguments, but I don't know what they want (got it from somewhere); it
does work. The form works, the database inserts data like I want. I
just need to know how to stop it from submitting based on invalid data
- and I don't want to use JavaScript. I can do that already. I want
to do it in .NET. Thanks for any help.

Nov 17 '05 #2
In your ValidateThis() you have to do something like this

RequiredFieldValidator1.IsValid = false

That will cause the submit to fail, I think.

Michael
"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have this CustomValidator:

<asp:CustomValidator runat="server"
OnServerValidate="ValidateThis"
Display="Dynamic"
ControlToValidate="txtMyTextBox"
ErrorMessage="Not a valid entry"/>

On my server side scripts, I have:

sub ValidateThis(obj as Object, args as _
ServerValidateEventArgs)

if len(args.Value) < 8 then
exit sub <---will this stop the submit from firing?
else
submit() <---what argument
end if

end sub

Sub submit(Source As Object, e As EventArgs)
... put stuff in a database too long to list
end sub

Okay, what I am trying to do is validate args.value (a textbox) and if
it meets or does not meet the criterion, then either stop everything
or submit to the database.

The problem is that no matter what I put in the ValidateThis sub, the
submit will always work. How do I use the OnServerValidate to stop
the entire page from submitting what's on the form. Also, if it does
pass my criterion, how do I get it too submit. Submit has the two
arguments, but I don't know what they want (got it from somewhere); it
does work. The form works, the database inserts data like I want. I
just need to know how to stop it from submitting based on invalid data
- and I don't want to use JavaScript. I can do that already. I want
to do it in .NET. Thanks for any help.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.524 / Virus Database: 321 - Release Date: 10/6/2003
Nov 17 '05 #3
Don't forget to add code like this at the beginning of the event that caused
the post back:

If Not Page.IsValid Exit Sub

Greg

"Michael Pearson" <mi************************@televox.com> wrote in message
news:e6**************@TK2MSFTNGP11.phx.gbl...
In your ValidateThis() you have to do something like this

RequiredFieldValidator1.IsValid = false

That will cause the submit to fail, I think.

Michael
"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have this CustomValidator:

<asp:CustomValidator runat="server"
OnServerValidate="ValidateThis"
Display="Dynamic"
ControlToValidate="txtMyTextBox"
ErrorMessage="Not a valid entry"/>

On my server side scripts, I have:

sub ValidateThis(obj as Object, args as _
ServerValidateEventArgs)

if len(args.Value) < 8 then
exit sub <---will this stop the submit from firing?
else
submit() <---what argument
end if

end sub

Sub submit(Source As Object, e As EventArgs)
... put stuff in a database too long to list
end sub

Okay, what I am trying to do is validate args.value (a textbox) and if
it meets or does not meet the criterion, then either stop everything
or submit to the database.

The problem is that no matter what I put in the ValidateThis sub, the
submit will always work. How do I use the OnServerValidate to stop
the entire page from submitting what's on the form. Also, if it does
pass my criterion, how do I get it too submit. Submit has the two
arguments, but I don't know what they want (got it from somewhere); it
does work. The form works, the database inserts data like I want. I
just need to know how to stop it from submitting based on invalid data
- and I don't want to use JavaScript. I can do that already. I want
to do it in .NET. Thanks for any help.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.524 / Virus Database: 321 - Release Date: 10/6/2003

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
2
by: RichieRich | last post by:
Does anyone know if it is possible? If I have two buttons on a page and in my OnServerValidate function can I figure out which button was pressed. I need to know because I have validators on the...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
3
by: Mike P | last post by:
I have 2 buttons on my ASP.NET page, one to Submit the user details and 1 to bring up a calendar. On the page I also have a custom validator which calls a procedure via OnServerValidate. The...
0
by: Rigs | last post by:
Hi, I have a textbox (txt1) with a Custom Validator (cv1) on a web form. The problem is that cv1's OnServerValidate method only fires when text exists in the textbox that cv1 is assigned to...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
6
by: tshad | last post by:
I have about 8 validators on my page and I want to show the error message next to or below the field that has the error, but I also want to put 1 message on the top of the page and one on the...
4
by: WebBuilder451 | last post by:
I have a check box for a confirmation that a new member has read the terms and conditions. This is an asp control, but can't seem to get a validator control to reconize it. What is the best way to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.