ASP.NET 2.0 Tips and Tricks
- Taking applications off-line: Adding an app_offline.htm file into the root of an ASP.NET Website automatically shuts down the application until the file is removed. That's a great feature for people that need a friendly message to be displayed while a particular server box is being updated.
- Cross-page postbacks: <asp:button PostBackUrl=“PostbackPage.aspx” runat=“server”/>. I've used these quite a bit in ASP.NET V2 and it's a really nice feature especially when a postback really needs to go to a different page such as a search page.
- Setting a default button: << DefaultButton=“btnSubmit” runat=server> This allows someone to hit the enter key and still have the button's postback event handler hit in the code-behind page. The DefaultButton property can also be added to Panel server controls.
- Setting default focus: <form DefaultFocus=“txtName” runat="server"> This allow you to easily set the default focus to a control in your form without writting code. The Page class's SetFocus() method can also be called. Controls also expose a Focus() method.
- Setting focus during a validation error: The validation controls now allow you to easily set focus on a control in error using the SetFocusOnError property. Validation controls also work properly in browsers such as FireFox. <asp:RequiredFieldValidator SetFocusOnError="true" ErrorMessage="TextBox3 is empty" ControlToValidate="TextBox3" runat="server“/>>
- Register server controls and user controls in web.config: You can now register frequently used server controls and user controls (ones used across multiple pages) in web.config which avoids having to define the <%@ Register %> directive in each page (which I personally never liked):
CSS Control Adapters: Prefer to use CSS and divs instead of tables for the HTML output by ASP.NET server controls? Now you can with CSS adapters.
0 comments: