Monday, March 26, 2012

Tabs

Does anyone know any good websites for using asp.net web controlled tabs dynamically. For example adding validation using the tabs.

Cheers

Jamie

What do you mean by:
>> adding validation using the tabs
Regards
I have a tab page which contains eight tabs. In each of the tabs is fields for a user to fill out. I was wondering when the user clicks on the next tab it will validate what was in the previous tab. e.g. they fll out their address details on one tab but forget to put in a postcode, I want it to validate this before they can access the next tab.
Cheers
This depends on if your tabs post back to update or not.
If they post back:
- Usually only the web controls that are visible in the tab are also marked Visible=true. All the rest are Visible=false. That prevents the validators that are invisible (or attached to invisible controls) from validating.
- The result allows the post back action to validate only the contents of the current tab. Its easiest on the server side, by calling Page.Validate() on the post back event handler for the Tab control (like its Click method). Then test Page.IsValid is true before allowing the tab to switch. If you want to add some client-side code to the tab's event that switches, you should call the same code used by submit buttons:
Page_ClientValidate()
If it returns true, continue switching tabs. False, stop switching tabs.
If they do not post back:
- This means all of the web control - even those that are hidden - are represented in HTML on the page. Those that are hidden have a style value of 'visibility:hidden' or 'display:none".
- If you were to call Page.Validate on the server side or Page_ClientValidate() on the client-side, all validators would fire. That includes the invisible ones. Those invisible ones would report an error (like the field hasn't been filled in yet via a RequiredFieldValidator). So it would not work.
- The solution is to use Validation Groups - available in ASP.NET 2.0 or myProfessional Validation And More. You define a group name for each tab. When you validate, you pass the group name for the tab into Page.Validate() or Page_ClientValidate().
- In addition, if you used my Professional Validation And More, the validators can be setup to detect that the data entry controls which they evaluate are invisible and will not attempt to validate them.

0 comments:

Post a Comment