Search Web

Tuesday, September 13, 2011

4 Small But Important Tips For Fresher of Asp.net.




Asp.net is a awesome framework developing web sites and web applications.with visual studio asp.net become cooler and cooler. I have wrote an article Visual Studio 2010 New Tips and Shortcut previously. now I thought to write for asp.net tips and tricks because as the way you are using the framework it’ll be hard or easier to understand and do some work with minimum codes.
Ok here we go we’ll see what are the cool features offer asp.net for .net web developers.

1. Maintain the position of scrollbar on postback : since asp.net 1.1 it was a very hard to maintain the position of scrollbar when doing postback. it’s was very necessary feature when we edit some data and after submit find position that we were editing. In asp.net 2.0 you can simply add the MantainScrollPositionOnPostBack attribute to the page directive.

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="..." Inherits="..." %>

2. Set Default Button for form when user hit the enter key : In asp.net 1.1 required to write javascript to set default key for when form submit after hit Enter key. fortunatly you can use HtmlForcontrol’s DefaultButton property to set which button should be clicked when the user hit the enter


<form id="frm" DefaultButton="btnSubmit" runat="server">

  ...

</form>


3. Set the default focus to control when page loads : as mention above also we can set default focus for page load like below




<form id="frm" DefaultFocus="txtUserName" runat="server">

  ...

</form>


4. Strongly type access to the cross-page postbacks : asp.net 2.0 introduced the concept of cross page post back where one page could post back information to another page.if you add public property in to code behind page that initiate the postback operation, you can access property in strong type manner by adding PreviouPageType directive in to target page of the post back.
<%@ PreviousPageType VirtualPath="Default.aspx" %>

by adding this directive to pageyou can access the TextBox defind in previous page in strongly type manner.

TextBox tb = PreviousPage.SearchTextBox;

1 comments:

Oliver Hicks said...

Asp.net is a awesome structure developing web sites and web applications.with visible studio room asp.net become chilly and chilly.

Post a Comment