Validation control not doing server side validation?

I think the subject covers what I'm asking.  I want to run some checks on the data that was entered after the page was submitted, but I don't know how to handle it if there's a problem the user has to go back and fix.  So I thought I'd try to work around the validation control to see how .NET handles it.  I have a text field that is required.  When the submit button is clicked, I assume some client side validation is run.  I get the validation message I want and the form won't submit.   But then I made a change in the on click event of the submit button - I set the text to "".  Now I'm expecting some server side validation to occur.  I was hoping to emulate whatever happened when I found a problem as described above so the user would experience a standard response if there was a problem with the data.  I didn't know what to expect, but it wasn't for the form to submit properly, except with an empty required field.

So where are my assumptin wrong, and what am I not understanding?

Diane

0
Mainship
1/22/2007 5:51:36 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies
599 Views

Similar Articles

[PageSpeed] 59

RequiredField validators are, by default, clientside only.

You'll want to use a Custom Validator and the validate event. You can fire it by checking "If Page.IsValid...."


0
Curt_C
1/22/2007 6:22:30 PM

Curt,

According to this: http://msdn2.microsoft.com/en-us/aa479045.aspx server side validation is the default.  Unless I'm really not understanding something?

Diane

0
Mainship
1/22/2007 11:21:14 PM

Validation on the server does occur by default.  However, from the link you posted...

 

"On the post-back, validation takes place during step 5, just before the event fires for the button..."

 

So, if you are  resetting the textbox value to "" in the submit event of the button, the server side validation has already happened.

0
S1nF0ny
1/23/2007 1:51:28 AM

That's right.  My book said that validation takes place both client side and server side, but books can be wrong, so I looked for more information before posting my reply.  I read it through, but never picked up on the point you just made.  So my test was flawed.

Thank you.  Now do you know why I can't enable the submit button when a  check box is checked?

Diane

 

0
Mainship
1/23/2007 3:38:57 AM

This concept is often missed. You *MUST* test Page.IsValid is true in your post back event handler before using the data. That will let the validation skip your code.

For more on this and other common validation questions, see http://aspalliance.com/699.


--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
1/23/2007 6:10:45 PM
Mainship:

That's right.  My book said that validation takes place both client side and server side, but books can be wrong, so I looked for more information before posting my reply.  I read it through, but never picked up on the point you just made.  So my test was flawed.

Thank you.  Now do you know why I can't enable the submit button when a  check box is checked?

Diane

 

Hi, Diane

Since you didn't tell us more details about your problem, hope this reference helps. 

It's easy to support server side validation. Microsoft has done most of the work for you. 

----------------------------------------------------------------------------------------------------------------

1. For the submit controls -- Buttons, LinkButtons, ImageButtons, and even the HtmlControl buttons -- they made the OnClick method automatically call Page.Validate() which validates all enabled controls on the page. All you have to do is add one statement inside your Click event method before executing code:

[C#]
protected void Submit_OnClick(object pSender, EventArgs e)
{
   if (Page.IsValid)
   {
      // your code here
   }
}
[VB]
Protected Sub Submit_OnClick(ByVal pSender As Object, ByVal e As EventArgs)
   If Page.IsValid Then
      ' your code here
   End If
End Sub

2. Other controls can post back. For example, a menu control or toolbar button. These controls have their own post back event handlers. They do not call Page.Validate() for you. So you need to make your post back event method first calls Page.Validate() and then tests that Page.IsValid is true.

[C#]
protected void MenuCmd1_OnClick(object pSender, EventArgs e)
{
   Page.Validate();
   if (Page.IsValid)
   {
      // your code here
   }
}
[VB]
Protected Sub MenuCmd1_OnClick(ByVal pSender As Object, ByVal e As EventArgs)
   Page.Validate()
   If Page.IsValid Then
      ' your code here
   End If
End Sub
----------------------------------------------------------------------------------------------------------------
Thanks.

Please give us feedback no matter whether you get your answer.
Please "mark as answer" if it's useful for you

Sincerely,
Jerome
0
Jerome
1/30/2007 5:31:09 AM

Thank you Peter, Jerome.

Jerome, does #2 apply to check boxes for example, as well? 

Diane

 

0
Mainship
2/1/2007 9:35:32 PM

Hi, there

Just an example :

<%

@ Import Namespace="System.Data" %>

<

script runat="server">

sub

Page_Load

if

Not Page.IsPostBack then

 

end

if

end

sub

sub

showMessage(s as Object, e as EventArgs)

lbl1.text=

"Check Box!"

end

sub

</

script>

<

html>

<

body><form id="Form1" runat="server">

<

p><asp:label id="lbl1" runat="server" /></p>

<

asp:CheckBox ID="cb" runat="server" AutoPostBack="true" OnCheckedChanged="showMessage" />

</

form></body>

</

html>

Help this helps.


Please give us feedback no matter whether you get your answer.
Please "mark as answer" if it's useful for you

Sincerely,
Jerome
0
Jerome
2/2/2007 1:50:20 AM
Reply:

Similar Artilces:

validation, is it better to have client side or use server side validator controls
 Hi All. I want to do validation on text boxes etc. Is it better to do client side validation or just use the server side validation controls?   Hi!  If for server side controls you mean RequiredFieldValidator, CompareValidator, RegularExpressionValidator, etc.. i can tell you that they use client and server validation. For instance if you use a RequiredFieldValidator, on the client will be a validation, but on the server this condition will be evaluated again. Probably one of the objetives of this is deal with client with javascript disabled. Of course I ...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Validator controls
To perform validation on the server using the validator controls, do i have to call the Validate method on each request or is there a way to set it to do this automatically?   Hi all, I have figured this one out. I realised I wasn't checking the IsValid property before changing the ActiveView of my MultiView control. ...

Server Side Validation vs Client Side Validation
If your page is using client side validation for required fields, expressions, etc.     What are the benefits or disadvantages of using 'extra' server side validation for max lengths, parsing, etc? Both have their Advantages and Disadvantages... so give this a read http://www.dotnetexpertsforum.com/viewtopic.php?t=172 Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET hi there, advantage: because you are using javascript some browsers for any reason may not sup...

client side validation vs server side validation
hello  i see a web form that consists of three controls :textbox,requiredfieldvalidator that weired to the textbox and a button within the click event of the button there is the following: if page.isvalid then response.redirect("Page is valid") else response.redirect("Page is not valid") end if according to my understandings: when the user does not fill anything in the textbox and then clicks the button the the page will not be submitted (i.e no request to the page will be happened or no postback will be happened) then no server event will be happened so it is sure when the us...

Server side validation affecting client side validation
Hi there I have some client side validation that is working fine and enables/disables buttons based on user selections. This works great. However, when I perform server side validation using custom validators (like checking if the user has entered < HTML > tags or decimals in the integer boxes) and the server side validation returns isValid = false then all of the JavaScript validation that I've already done when the user clicked each control is lost. I don't understand why the enabled/disabled state of the control is not maintained.  What is calling the JavaScr...

Controlling the controls a validator validates
Hello, I want to control which controls appear for a validator when they go to controltovalidate dropdown in property grid.  Is the solution to create a designer for the control?  How do you regulate that?  I can't override the ControlToValidate property... Thanks.Brian"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4). Well ur logic is true, thats the way, what u need to do is not override the property (cant), create another property, that implemen...

restricting Validation on server side if user side validation is done
I was facing a problem a majot trouble. IF we disable scripts and third party browser extentions then validators goes down, they jus stop working data goes straight in database. to restrict injection (sql as well as scripts and other) i need to perform server side validations. I am using regex to validate in code behind(.cs file) of aspx pages. But that code will execute even if client side validation is performed. I want a way to notify, means to restrict code to execute if client side Vlidation suceeds. Is there any way please help.  Hey, This is a common problem. On the serv...

avoiding redundant server-side validation after client-side validation
I see an inaccurate validation behavior on my asp.net (2.0) form. The EnableClientScript property of my validation control is set to True by default, so it performs the validation on clientside. But as soon as this occurs, it also performs the server-side validation, so the page refreshes. When the validation error occurs on clientside, it should not do the validation on serverside (I'm not calling Page.Validate() or doing Page.IsValid). In my past experience, asp.net handled this automatically, but I guess it's not always the ca...

Summary Validation Doesn't work for Custom Vlidation Control ,Server side validation
I have many validation controls, one of which is custom validation control. All the validation controls run on client side show proper validation summary message. But for Custom validation control, the validation summary doesn't show anything which runs on server side. Why? My sample code is as follow.protected void CusValSponsorName_ServerValidate*object source, ServerValidateEventArgs args*    {        string[] names = sd.getSponsorName("Select SponsorName from Sponsor");        foreach *string name in nam...

validation controls
Hi all,I have a web form with a few controls and reqdfield, compare & regex validation controls. On all validation controls i have enabled the client script property. Yet when I submit the form it does a postback to do the validation. Any ideas? I am running vs2005 beta 2.TIA! Hello.how do these validators perform the validation of the other controlos? whar browser are you using?-- Regards,Luis Abreuemail: labreu_at_gmail.comEN blog:http://msmvps.com/blogs/luisabreu Well they are regular requiredfield, regex & compare validators. Browser is latest version of Firefox. I had to use...

Validator Callout server-side validation
The toolkit demo says this:" The callouts do not currently display automatically after a server post-back and will only work for custom validators which utilize client-side validation. Even after a post-back the callout will display when the form is re-validated when a postback is attempted again."  It has said this since the control was released. Will the validator callout ever support server-side validation? Is there a way to force the callout to display after a server-side validation?  ...

Validation controls does not validate on production server
  Hi,ASP.NET 1.1 My validation controls does not validate on the production server. The controls works fine on development environment and on QA/Test environment. It really drives me nuts. Anyone who has experience/solution with this?  Regards from Sweden Cheers Christoffer   I hd this exact same issue before.  When 1.1 first came out it had a js file for client-side validation with the new validation controls.  When the updated 1.14 came out it didnt properly move over the updated js file to the correct .net folder.  From a post on ...

Validators
Hello, I've come across the problem when I wanted to use client side validation (no matter of which type) depending on the input from a different control. The scenario is: I have two textboxes A and B. A does not need to be validated (no validator associated with A). The textbox B has to be validated if and only if the A has any value. I know this is trivial with custom validator in the server side mode... But unfortunately I want it to run the validation on the client side. And I also know that I can write a javascript function for the ClientValidationFunction and hardcode client id ...

Web resources about - Validation control not doing server side validation? - asp.net.getting-started

Cross-validation (statistics) - Wikipedia, the free encyclopedia
is a model validation technique for assessing how the results of a statistical analysis will generalize to an independent data set. It is mainly ...

Serena Williams eyes history, Caroline Wozniacki craves validation in women's US Open final
As Serena Williams eyes another slice of tennis history, Caroline Wozniacki is craving validation with a watershed US Open final triumph on Sunday ...

Travers Duncan asks High Court to strike down ICAC validation laws
ICAC could be sent back to the High Court as a challenge to new laws validating corruption findings looms.

Adam Scott proclaims Texas win as validation of No.1 ranking
... No.1 golfer, beating American Jason Dufner in the third hole of a play-off at the Colonial event. "It's a good feeling and maybe some validation ...

Hollande to sign gay marriage bill after Constitutional Council's validation
Hollande to sign gay marriage bill after Constitutional Council's validation People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, ...

Marketers, Get Ready for the 'Validation Era'
The public brands included has been engaging in a "friends" arms race. But there are signs that we know we overdid it.

Validation and Uncertainty
What an extraordinary conversation I had recently on Twitter. It started with Neil Killick’s statement that we should not consider our stories ...

Nvidia Icera 410 LTE Modem Passes AT&T Network Validation
... Today's news is a small step and logical precursor toward both goals, Nvidia's Icera 410 LTE and HSPA+ baseband has passed AT&T's network validation ...

Ting’s Q1 Subscriber Growth Suffers from Sprint’s New Unlocking Validation Process
Back in February, Sprint updated the process it uses to validate unlocked devices that customers want to utilize on other carriers or one of ...

[Android M Feature Spotlight] Stricter APK Validation Now Actually Checks If All Of An APK's Files Are ...
While you might file this one under "really? We weren't doing this already?" if you're a security expert, Google has added stricter validation ...

Resources last updated: 12/22/2015 7:04:08 AM