How to update controls which are outside of updatepanel during partial page rendering?

we generally used update panel to do the partial page postback, which means to postback the controls which are only inside the update panel. For achieve this we simply call Update() method for the corresponding Update Panel. This thing is quite simple when we are trying to update any control which is inside the updatepanel itself. But, The problem may come when we want to update the controls which are outside of UpdatePanel and we need to update the same while updating then control inside updatepanel.

To make it simple. Let’s consider below scenarios. In our web page, we have Two labels (Label1 and Label2). Lable1 present inside the updatePanle and Label2 is in the outside of updatePanel. We have one Button say Button1, which is also inside the UpdatePanel. Now, our requirement is to update the Label2 while we are updating Label1 by Clicking Button1.

below is the code block for above scenarios

      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional>
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Button ID="Button1" runat="server" Text="Update Button"  onclick="Button1_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
     <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

Now, if we click on “Button1″, it will update only the content of Label1 not Lable2.

The solutions is to use ScriptManager.RegisterDataItem() . Using RegisterDataItem() methods we can register any control with the Particular Page ScriptManager Instance. While registering we need to provide the Control name along with the data item for the control which we want to render. Continue reading

How to get list of all active HttpModules in ASP.NET?

Here is a quick tips to get the list of all active HTTPModules at runtime.  We can get the list of all HttpModules from the web.config or from machine.config file. But, what we need to do if we want to get the list of all active HttpModules during runtime? Yes. We can easily get the details with the help of  HttpApplication and HttpModuleCollection Class. If we quickly recall the IIS Process Request [One detailed Article], when a request reaches to worker Process from client browser, First of all Worker process is responsible to start and HttpRuntime by loading ISAPI filter. After that HttpRuntime load an HttpApplication object with the help of  HttpApplicationFactory class. Each and every request should pass through the corresponding HTTPModule to reach to HTTPHandler, this list of module are configured by the HTTPApplication. Below is the code snippet by which we can get the list of active HttpModules.

        //Get Application Instance from Current Content
        HttpApplication httpApps = HttpContext.Current.ApplicationInstance;
        //Get List of modules in module collections
        HttpModuleCollection httpModuleCollections = httpApps.Modules;
        Response.Write("Total Number Active HttpModule : " + httpModuleCollections.Count.ToString() + "</br>");
        Response.Write("<b>List of Active Modules</b>" + "</br>");
        foreach (string activeModule in httpModuleCollections.AllKeys)
        {
            Response.Write(activeModule + "</br>");
        }

Below is the sample output :

This can be quite useful when we want to check if our custom created  module loaded successfully or not .

Shout it

“CompressionEnabled” Session in ASP.NET 4.0

Session is the most important state management mechanism for a web application. In ASP.NET we are having two type of state management

1. In Process

2. Out Process

In process” is the by default session storage mode for ASP.NET Web application. When it comes under Out Process we can use either of state server or SQL Server to persist our session data.

Here I am going to describe one new features added in ASP.NET 4.0 realted with Session. If you want to know about when to use session, what session mode to use, how to configure the session storage please read one of my article “Exploring Session in ASP.NET” published at CodeProject.

In case of In Process, session data stored in In memory of worker process. But when we are talking about “OutProc” session mode, we need to ensure that session data should be “Serialized” first  . So, when we are moving session data from Web Server to Out Process Server ( State Server or SQL Server ) it can be a performance overhead based on the size of data that we are stroing in Session.

ASP.NET 4.0 comes us with a new option for compressing the Session data with Out Process Session mode. To enabling this functionality we need to add “compressionEnabled=”true” attribute with the SessionMode in web.config . Web.config entry would be look like below,

<sessionState mode="SQLServer" sqlConnectionString="Integrated Security=SSPI; data source=.;" <em>compressionEnabled="true" </em>allowCustomSqlDatabase="true">

This will compress / Decompress the session data during serialization / deserialzation of session data. ASP.NET 4.0 used System.IO.Compression.GZStream class to compress the session mode. One more important things to remember that use of compression mode is useful when we are storing large number of data in session because for every request it will going to use Gzip Compression/ Decompression going to be used to access the session variable.

Hope this will helps you !

Shout it