Detect AJAX postback in Global.asax

by demtron on Friday, January 16, 2009 08:19 AM

I was recently working on a page hit logging scenario that, for reasons having to do with URL rewriting, needed to have the logging code executed in the Application.BeginRequest event of Global.ajax.  The application relies heavily on ASP.Net Ajax, and I needed a was to ferret out the AJAX requests and not log them.  Ordinarily, in the page lifecycle, this would be accomplished by using Page.IsAsync.  In this case, I needed to perform the logging prior to the page code being invoked.

To determine the whether the request was generated by AJAX, I used the following code:


Request.Headers("X-MicrosoftAjax") = "Delta=true"


Request.Headers["X-MicrosoftAjax"] = "Delta=true";

Hope that helps someone out there who has struggled to find an easy answer.

Centering a DIV Window with Cross-Browser JavaScript

by demtron on Wednesday, January 14, 2009 02:28 PM

Years ago, I wrote a little bit of JavaScript to position a DIV control in the center of a browser window space by calculating the browser area, the window size, then determine the coordinates of the place where the DIV would need to be placed.  Since I forgot where I put it and it brobably wouldn't be cross-browser compatible anyway (orginally written for IE 5/6), I searched the web and ran across this JavaScript centering code that accomplishes exactly that.  Here are the excerpts of the code needed to do this.

window.size = function()
var w = 0;
var h = 0;
//strict mode
if(!(document.documentElement.clientWidth == 0))
w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
//quirks mode
w = document.body.clientWidth;
h = document.body.clientHeight;
w = window.innerWidth;
h = window.innerHeight;
return {width:w,height:h};
} = function()
var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
var _x = 0;
var _y = 0;
var offsetX = 0;
var offsetY = 0;
//strict mode
if(!(document.documentElement.scrollTop == 0))
offsetY = document.documentElement.scrollTop;
offsetX = document.documentElement.scrollLeft;
//quirks mode
offsetY = document.body.scrollTop;
offsetX = document.body.scrollLeft;
offsetX = window.pageXOffset;
offsetY = window.pageYOffset;
_x = ((this.size().width-hWnd.width)/2)+offsetX;
_y = ((this.size().height-hWnd.height)/2)+offsetY;

Here's some example code to show how it's supposed to be used:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<script type="text/javascript" src="Window.Size.js"></script>
<script type="text/javascript">
function showCenter(point)
var div = document.createElement("div"); = "#dedede"; = "absolute"; = point.y + "px"; = point.x + "px"; = "100px"; = "100px";
<div style="height:1200px"></div>
<input type="button" value="Get Center" onclick="showCenter({width:100,height:100}))"/>


Telerik Control Problems with Intellisense

by demtron on Tuesday, December 16, 2008 05:09 PM

When reinstalling Visual Studio and accessing Web projects that use Telerik RadControls for ASP.Net Ajax, I've found that Intellisense is generally broken for that project and only for Telerik components.  Furthermore, design-time support is also lost.  Here is a list of fixes to try in order to solve this.

  1. Check whether the correct version of the components are in the GAC.
  2. If the site is running on a network share, be sure that the UNC share has fully trust by the .Net framework.  This can be entered at Start -> Control Panel -> Administrative Tools -> Microsoft .NET Framework 2.0 Configuration -> Console Root -> .NET Framework 2.0 Configuration -> My Computer -> Runtime Security Policy -> User -> Code Groups -> All_Code, then add a child code group with file:////\\computername\sharename\* with Full Trust permissions.
  3. Right-click the assembly in the /bin folder of the project and click Update Reference.

Browser Detection for ASP.Net Ajax

by demtron on Tuesday, November 04, 2008 10:17 AM

Here's a class that I found in client-side Microsoft AJAX library for browser detection.  It's Sys.Browser.Agent.  For a while, it wasn't documenated anywhere in the Microsoft on-line documentation, but it must have just appeared recently at:

One example of how this class can be used:

if (Sys.Browser.agent == Sys.Browser.InternetExplorer) 
    alert("Display this message for IE visitors");

For Sys.Browser.agent, the four values it can return are:

  • Sys.Browser.InternetExplorer
  • Sys.Browser.Firefox
  • Sys.Browser.Safari
  • Sys.Browser.Opera

Powered by BlogEngine.NET
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share


<<  June 2024  >>

View posts in large calendar
Log in

Milwaukee SEO Company

Milwaukee Access Programmer/Developer

Milwaukee Website Designer and Developer

Marketing / SEO

Blog Directory
blogarama - the blog directory
Milwaukee area SEO, SEM, ASP.Net