when do we have to call the method Vaildate() and when there is no need to call it,because i noticed that in some examples they called it,and in others they did not.
When you need to validate that a user input is valid. If you have atextbox that users type a number into, and that number has to bebetween 5 and 50, you can create a validator that checks the valueagainst the range. If the number is too high or too low, you display anerror and NOT process the input/page.
Thats a simple example- there are more complex types of validation.
If you don't have user input ,or are not concerned with what that input may be - you don't need to validate
HTH
The Button, LinkButton and ImageButton controls automatically call Validate() for you after Page_Load and immediately before calling their Click event handler (where you save the data). If you set CausesValidation=false on these controls, they do not call Validate().
You must test Page.IsValid is true inside your Click event handler method.
For a better understanding of validation, see this article:www.aspalliance.com/699.
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 callPage.Validate() for you. So you need to make your post back event method first callsPage.Validate() and then tests thatPage.IsValid is true.
i didnt really get what si a menu control,and toolbar button :S any examples or explination ?
Third parties have created other types of web controls including menus (they look like a drop down menu in a Windows program) and toolbars (they look like the buttons along the top of your browser). These web controls invoke commands that usually post back. Validation is often appropriate on a post back because you intend to use the data entered on the page.
You can locate the various third party controls at this site's Control Gallery,www.123aspx.com, andwww.411asp.net. Many of the "Suite" products (Infragistics, Telerik r.a.d. controls, etc) include these controls.
thanks
0 comments:
Post a Comment