This is a migrated thread and some comments may be shown as answers.

Can someone please explain this simple concept?? (basic validation)

4 Answers 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 05 Apr 2011, 12:59 PM
So so so f*cking frustrated. New to ASP.NET and I can't get my head around the simplest concepts.

I have basic 'required' validators on fields - but when is the validation summary/error messages produced?

For example check this link (which is extremely similar to what I'm doing): http://www.aspxcode.net/free-asp-net-validation-source-code.aspx?Topics=How%20to%20Use%20ValidationSummary

When the button is clicked is when the validation "happens." But how? The code behind the button doesn't handle this!? 

I know this is not yet telerik-specific but once this question is answered I have another question regarding telerik-control specific validation (which may be solved depending on your explanation and my grasp of it).

Thanks a lot, any help and basic understanding here will be very much appreciated,

Dan

4 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 05 Apr 2011, 01:16 PM
Hello Daniel,

From the link you provided I can see that in the OnClick event handler of the ButtonOK  - all controls are validated via the Page.IsValid property:

Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If Page.IsValid Then
            lblSum.Text = "you pour the data is correct."
        End If
    End Sub
End Class

Please take a look at this MSDN article for more information on the IsValid property with examples.

Best wishes,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Daniel
Top achievements
Rank 1
answered on 05 Apr 2011, 01:24 PM
Thanks Veronica, I'll make sure I read all of that article and try and get a better understanding of it. I didn't quite mean at what point is the page/its input evaluated as to whether it was valid or not, I meant sort of when is the validation done.

I might be wrong, but I'm currently thinking of the process as:

-User inputs data
-SOMETHING triggers off the validators and makes them look at the data inside of the controls they are validating
-Validators passes data to validation summary
-Validation summary then displays data

But I don't understand what "triggers" the validators, at what point in the life cycle of the page or usage of the page???

For example, if I were to create a windows form, I know that I'd probably implement validation by checking the contents of a textbox control on the Leave or LostFocus event. The user physically clicking or navigating away from the textbox would call a method I had written to do whatever I needed it to do in terms of validation. It's a clear event, with a clear consequence - but I don't see how, what and when these basic asp validation controls are called??

Thanks again, really appreciate your patience.
0
Daniel
Top achievements
Rank 1
answered on 05 Apr 2011, 01:32 PM
For a real 'lite' version of validation I can't grasp:

http://www.w3schools.com/aspnet/showasp.asp?filename=demo_validationsum

It's evidently something to do with the button, but that button doesn't handle any sort validation, so I'm assuming the validation is done upon any control causing ........? Postback? Any type of page refresh? I suppose this is what I'm stuck on when it boils down to it.

Thanks again.

EDIT: Should also note - if I were to not enter a name on the form on the above example, it would put the red asterisk but for some reason not render the validation summary until the button is clicked?
0
Accepted
Veronica
Telerik team
answered on 10 Apr 2011, 11:44 AM
Hello Daniel,



Yes, your assumption of the validation process with steps is correct. And yes - the validation on the page is caused by postback (in our case submitting the button). Here's some more information on this:



The validation controls work in cooperation with the Page object. ASP.NET uses the Page object and the validation controls together to ensure the data coming from the client is still valid when it gets to the server. The Page class has a Validators property that contains a collection of all the validation controls defined on the page. The Page class has also a Validate method. You call this method to ask the Page to check each of the validation controls and to determine if anything on the page is not valid.



ASP.NET calls the Validate method automatically after the page's Load event handler method executes. Therefore, once the page has loaded you can find out if the page is indeed valid on the server. To do so youcall the Page.IsValid property (set by the Validate method). This property is of type boolean and is only true if all validation controls process correctly.



I hope that this explanation makes the ASP.NET Validation more clear.  



Greetings,

Veronica Milcheva

the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or