Thursday, March 29, 2012

server side validation

Hi,
Does anybody has a simple example (other than what is on Microsoft's site) of how to do server side validation? I simply can not get it to work and Microsoft example is king of vague to me. All I am trying to do is compare the value of a textbox against a database value and reject if it is not valid. So if the query
select* from thistable where name=textboxvalue
returns zero rows then the validator should fail.
Thanks,
Mo
Can you show the code that you are using that doesn't work? Maybe its just a little tweak away from working
1. Use a CustomValidator with its EnableClientScript property set to false (since you only can do server side validation)
2. In the ServerValidate method, write code that checks with the database. It should set the args parameter's IsValid property to true if the validator should succeed and false if it should fail.
3. You should have a post back event handler for each submit control. For example, Buttons have a Click event. Inside that code, test Page.IsValid is true before saving data. If you are not using any of the buttons or if the Button control's CausesValidation property is set to false, first call Page.Validate() before testing IsValid.
To learn all kinds of things about validation, see this article:www.aspalliance.com/699.

No comments:

Post a Comment