Posts

Showing posts from October 12, 2008

ASP.NET State Management

ASP.NET State Management If the page is posted to the server then all the information associated with page and the controls on the page would be lost with each round trip, because new instance of the web page class is created each time when page is posted to the server. For example, , if a user enters information into a text box, the information would be lost after the page is posted to the server.To overcome this inherent limitation of traditional Web programming, ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows: (A) Client-Based State Management: 1. View state 2. Control state 3. Hidden fields 4. Cookies 5. Query strings All above involve storing data on the client in various ways. (B) Server-Based State Management: 1. Application state 2. Session state 3. Profile Properties application state, session state, and profile properties all store data in memory on the server. Each option has

ASP.NET Page Life Cycle Overview

ASP.NET Page Life Cycle Overview When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. It is important for you to understand the page life cycle so that you can write code at the appropriate life-cycle stage for the effect you intend. Additionally, if you develop custom controls, you must be familiar with the page life cycle in order to correctly initialize controls, populate control properties with view-state data, and run any control behavior code. (The life cycle of a control is based on the page life cycle, but the page raises more events for a control than are available for an ASP.NET page alone.) For more information, see http://msdn.microsoft.com/en-us/library/ms178472.aspx

ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0

ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0 This topic outlines the life cycle of ASP.NET applications, listing important life-cycle events and describing how code that you write can fit into the application life cycle. The information in this topic applies to IIS 5.0 and IIS 6.0. For information about the ASP.NET application life cycle in IIS 7.0, see ASP.NET Application Life Cycle Overview for IIS 7.0 . Within ASP.NET, several processing steps must occur for an ASP.NET application to be initialized and process requests. Additionally, ASP.NET is only one piece of the Web server architecture that services requests made by browsers. It is important for you to understand the application life cycle so that you can write code at the appropriate life cycle stage for the effect you intend. see more details: http://msdn.microsoft.com/en-us/library/ms178473.aspx

Using Forms Authentication with ASP.NET AJAX

Using Forms Authentication with ASP.NET AJAX: You can use the Microsoft AJAX Library application authentication service to verify credentials that are stored as part of the ASP.NET membership service. This topic shows how to call the application authentication service from the browser by using JavaScript. You can access the authentication service from client script by using the AuthenticationService class, which supports the following methods: login . This method validates the user credentials by using the default membership provider. If the credentials are verified, the method sends a forms authentication cookie to the browser. Most ASP.NET AJAX applications will use the login method, because forms-authenticated applications require an authentication cookie in the browser. logout . This method clears the forms authentication cookie. Configuring the Server: The server provides the infrastructure to process the identification credentials such as name and password from a user, and to v

Disable back button of Browser in asp.net

This function use for disabling back button of browser. If you want prevent to go back from browser so use follwing method instead of response.redirect(); public string Disable_Back_Button(string nextpage_url) { try { string strScript; strScript="<script language="javascript">"; strScript=strScript+"{"; strScript=strScript+" var Backlen=history.length;"; strScript=strScript+" history.go(-Backlen);"; strScript=strScript+" window.location.href='" + nextpage_url + "'; "; strScript=strScript+"}"; strScript=strScript+"</script>"; return strScript; } catch(Exception ex) { throw ex; } } Example for use: Response.Write(Disable_Back_Button("nextpage.aspx")); instead of response.redirect("nextpage.aspx");

Javascript alert from ASP.net code behin

Javascript alert from ASP.net code behin you can display javascript alert from code behind C# code: public string Javascript_Alerts(string msg) { string popupScript; popupScript = " <script language='javascript' >" + "alert('"+msg+"') </script >"; return popupScript; } Example for use Response.write(Javascript_Alerts("your msg");

Populate data in dropdown in asp.net

Populate data in dropdown in asp.net: C# Code: using System.Data; using System.Data.SqlClient; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection cn = new SqlConnection("Server=localhost;database=test;uid=sa;pwd="); SqlDataAdapter da = new SqlDataAdapter("Select ID,productName from Products", cn); DataSet ds = new DataSet(); try { da.Fill(ds); DropDownList1.DataSource = ds.Tables[0]; DropDownList1.DataTextField = "productName"; DropDownList1.DataValueField = "ID"; DropDownList1.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } finally { cn.Close(); da.Dispose(); ds.Dispose(); } } }

Display data in GridView in asp.net

Display data in GridView in asp.net: using System.Data; using System.Data.SqlClient; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection cn = new SqlConnection("Server=localhost;database=test;uid=sa;pwd="); SqlDataAdapter da = new SqlDataAdapter("Select * from Products", cn); DataSet ds = new DataSet(); try { da.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } finally { cn.Close(); da.Dispose(); ds.Dispose(); } } }