Showing posts with label Webforms. Show all posts
Showing posts with label Webforms. Show all posts

Monday, September 28, 2015

ASP.NET Concurrent Ajax Requests and slow performance

While working on a client project I came across an interesting issue. That is when concurrent Ajax requests (originating from Jquery ajax) came in the asp.net web service (A set of aspx web methods in this case) were performing ridiculously slow. The methods it self were executing pretty fast. It turned out that when you have "[WebMethod(EnableSession = true)]" the requests are processed sequentially with in the same session.

The fix is to make the session read only, that is if your web methods are not modifying the session.

If any other page methods are modifying the session then the best approach is to move your web methods to a different aspx file and make the session read only for that page. Below given is the page directive for doing that,

<% @Page EnableSessionState="ReadOnly" %>

Hope this helps.

Saturday, May 24, 2014

ASP.Net Webforms Inline tags and code blocks

There are many elements inside a webforms (.aspx) page. To somebody beginning asp.net webforms these may seem quite similar and be confusing at first. (Well it was for me when I started learning asp.net webforms)
So hopefully this might help another soul.

Elements of a asp.net page (Inline tags and code blocks) can be listed as follows,

1. Directives

These come in many flavors like Page directives,
 ex : <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Trace="true" %>

or  Import directives,
ex : <%@ namespace="System.Drawing" %>

There are many more directives other than these two.

2. ASP.Net expressions

This is expression builder syntax, typically used to get values from web.config
ex: <%$ ConnectionStrings:AdventureWorks2008 %>  

3. User Controls

These are references to user created controls which are similar to web controls that enhances reusability 
ex: <PH:MainMenu Title="Menu Control" id="mainmenu" runat="server" />

4. Render blocks

Used for outputting elements like variables
ex:  If you have a variable named age then,
<%= age %>
will output the value of age

5. Code blocks

These are similar to javascript tags just that these run on the server,
<script runat="Server" language="c#" > ....some server side code here .... </script>  

6. Server Controls

These are the controls we drag and drop from the designer (Labels, Buttons etc)
ex: <asp:Label id="myLabel" runat="Server" />

7. Data binding controls

Used for biniding expressions such as Eval or Bind, these are typically used with data controls like Gridview
ex : <%# Eval("DBFieldName") %>