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:

VB.Net

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

C#

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

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


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.

Control Focus, AJAX UpdatePanel Postback and Cursor Position

by demtron on Thursday, December 04, 2008 05:19 PM

When using ASP.Net AJAX to perform a postback from within a textbox input control, I found that the textbox loses focus after the postback.  To overcome this, I added the following code:

ScriptManager.GetCurrent(Me.Page).SetFocus(MyTextBox)

However, upon setting focus back to the textbox, the cursor lands at the beginning of the text in the control.  To solve this, just add the following JavaScript on the page or within window.setTimeout:

var textInput = $get('MyTextBox');
if (textInput.createTextRange)
{
    var range = textInput.createTextRange();
        range.moveStart('character', (textInput.value.length));
        range.collapse();
        range.select();
    }

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:

http://msdn.microsoft.com/en-us/library/cc679064.aspx

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 1.5.1.18
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share

Calendar

<<  April 2024  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

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
TopOfBlogs
Milwaukee area SEO, SEM, ASP.Net