Wednesday, December 2, 2009
Wednesday, November 11, 2009
DataList Control
DataList Control of ASP.Net 2.0 provides the functionality to display the data in form of ordered or unordered list of items. DataList control includes different types of templates that also enable you to select, edit, update or delete the data items. You can organize the data items bound to the DataList control using simple HTML markup tags inside the templates. ItemTemplate field is the most necessary element of the DataList control that enables you to display the retrieved data items from any datasource. There are style templates also that can be used to customize the appearance of list items of DataList. Following are the types of templates of ASP.Net 2.0 DataList control:
1. ItemTemplate: This is the main template that displays the data content retrieved from the datasource in the specified layout and CSS style applied to it. ItemTemplate is the required template of DataList control.
2. AlternatingItemTemplate: You can define the alternate style for the data content that is to be displayed inside the DataList. Alternate template renders the data items according to the specified layout and appearance styles associated to it. If AlternateTemplate is not defined then DataList control renders the ItemTemplate only.
3. SeparatorTemplate: It allows you to separate the repeat layout of list items inside the DataList control. SeparatorTemplate renders the specified separator character, text or any HTML markup tag between items as well as alternating items.
4. SelectedItemTemplate: It displays the content with specified style and layout applied to the selected item template. SelectedItemTemplate renders only when selected index changed event of DataList control fires.
5. EditItemTemplate: You can place the textbox controls inside this template for the data fields to allow the users to update the old value with new one. EditItemTemplate renders when DataList control receives the edit command event signal.
6. HeaderTemplate: You can display the heading at the top of list items by specifying customized appearance for the header text.
7. FooterTemplate: Similar to HeaderTemplate you can also add the footer text with customized appearance under the DataList control’s data items.
Tuesday, October 20, 2009
State Management in Asp.Net
State Management
State management is defined as a process of maintaining state and page information over multiple page requests.
2 Types:-
Client side State Management
- View state
- Hidden fields
- Cookies.
- Query String
The ViewState property provides a dictionary object for retaining values between multiple requests for the same page. The ViewState indicates the status of the page when submitted to the server.The status is defined through a hidden field placed on each page.
The Hidden field stores a variable in its value property and is explicitly added to the page.
A Cookie is a small amount of data that is stored in the client machine or in the memory of a client browser session. It contains site specific information that the server sends to the client along with a page output. Cookies can be temporary or have specific expiration dates.
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie c = new HttpCookie("my cookie");
c.Value = "hello";
c.Expires = System.DateTime.Now.AddDays(7);
Response.Cookies.Add(c);
}
protected void Button1_Click(object sender, EventArgs e)
{
string s;
s=Request.Cookies["my cookie"].Value.ToString();
Response.Write(s);
}
Query string is the limited way to pass information to the web server while navigating from one page to another page. This information is passed in url of the request.
In Default.aspx
if (TextBox1.Text == "aa" && TextBox2.Text == "mm")
{
Response.Redirect("default2.aspx?name="+textbox1.text+"&pwd="+textbox2.text);
}
Give this code in Default2.aspx
protected void Page_Load(object sender, EventArgs e)
{
Response.write(Request.Querystring["name"].ToString());
Response.write(Request.Querystring["pwd"].ToString());
}
Sever side State Management
- Application
- Session
The Session state is scoped to the current browser session and the number of session states will be determined by the number of users using the application. The session can be different for each visit by the user.
Subscribe to:
Posts (Atom)