Tuesday, February 17, 2009

How to Clear All Values in Page -tutorials and code snippet

How to Clear all controls values like TextBox1,DropDownList?

We can get Page controls from Page.Controls. each controls are child controls of other page element in
protected void Button1_Click(object sender, EventArgs e)
        ClearAllControlsValues(Page.Controls, 0);

    private void ClearAllControlsValues(ControlCollection controls, int depth)
        foreach (Control ctrl in controls)
            if (ctrl.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                TextBox txt = (TextBox)FindControl(ctrl.ID);
                if (txt != null)
                    txt.Text = string.Empty;
            if (ctrl.GetType().ToString() == "System.Web.UI.WebControls.DropDownList")
                DropDownList dDownList = (DropDownList)FindControl(ctrl.ID);
                if (dDownList != null)
                    dDownList.SelectedIndex = 0;
            if (ctrl.Controls != null)
                ControlCollection(ctrl.Controls, depth + 1);

What is ViewState Chunking in ASP.Net - Definition & Solution

What is ViewState Chunking

Size of hidden viewstate have no limit.some poxy and firewalls refuse page loads if they have hidden file have greater than certain size. to solve this problem by viewstate chunking.ViewState Chunking is automatically divide view state multiple field to ensure that no hidden field overcome max size. viewstate chunking is not a method for good performance, its only for some proxys and firewalls.
for viewState chunking u can set the maxPageStateFieldLength attribute of the <>
element in the web.config file
< maxpagestatefieldlength="1024">< / pages >
< /system.web >

Sunday, February 15, 2009

Page Caching in ASP.Net - enable and disable client cache

How to Enable Page output caching in ASP.NET?

ASP.NET provides easier methods to control caching. You can use the @ OutputCache directive to control page output caching in ASP.NET. Use the HttpCachePolicy class to store arbitrary objects, such as datasets, to server memory. You can store the cache in applications such as the client browser, the proxy server, and Microsoft Internet Information Services (IIS). By using the Cache-Control HTTP Header, you can control caching.

Some datas are not requried to reload all time when clint attempting to server. we can save ouput page cache in Client side.

method 1

Take ISS (Inertner Information Service) form machine. select site then take properties then
select HTTP Headers Enable content Exparation. this Set your sites output cache properties

Method 2

we Can add Programmatic
Declarative method
<%@ OutputCache Duration="60" VaryByParam="None" %>
Turn off Caching