Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Monday, March 12, 2007

ASP.Net AJAX offers a few helper routines for writing debug/trace statements in your clientside scripts. One of these helper routines is Sys.Debug.trace(), and it is really only a thin wrapper over a block of code that identifies the host browser and then utilizes its built-in tracing facilities.

Within MicrosoftAjax.js you'll find that trace() internally calls appendConsole(). The internals of appendConsole() looks like this:

if(typeof Debug!=="undefined"&&Debug.writeln)
   Debug.writeln(a);
if
(window.console&&window.console.log)
   window.console.log(a);
if(window.opera)
   window.opera.postError(a);
if(window.debugService)
   window.debugService.trace(a);

The first conditional is detecting if you're running Internet Explorer by seeing if Debug and Debug.writeln have definition. An example of what Debug.writeln() does can be found here.  

It appears as though window.console.log() is for Safari, window.opera.postError() is for Opera (obviously), and window.debugService.trace() is for WebDevHelper (I believe). I don't see one for FireFox, does FireBug not have tracing support? Certainly it must.....


kick it on DotNetKicks.com
Monday, March 12, 2007 1:13:01 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
AJAX | ASP.Net
 Friday, March 09, 2007

Say you have a situation where you want to catch all unhandled web errors in your global.asax file. You reimplement part of your site in ASP.Net AJAX and suddenly some exceptions that were being caught are no longer caught, the question is, what's happening?

The answer lies within the PageRequestManager: the server-side "brains" of ASP.Net AJAX. This object is a control just like any other when used on an ASP.Net page and registers for errors on the page within it's OnInit() method:

if (_owner.IsInAsyncPostBack) {
_owner.IPage.Error += OnPageError;
}

The IPage reference is a reference to a page wrapper that ASP.Net AJAX uses internally; suffice it to say that it's simply registering for the event fired when an unhandled exception occurs on a page - that part is nothing new to AJAX.  

What happens, though is that the following block of code gets executed within the OnPageError() handler if you do not have custom errors redirect enabled:

if (showAsyncErrorMessage) {
_owner.IPage.Response.Clear();
EncodeString(_owner.IPage.Response.Output, ErrorToken, httpCode.ToString(CultureInfo.InvariantCulture), errorMessage);
_owner.IPage.Response.End();
}

The page response gets cleared, a special blob of text gets inserted, and then the response stream ends. Doing this effectively wipes the page response (including any error information in it) away - thereby short-circuiting the ability for your handler method in Global.asax to get called.

Run Fiddler on your machine to see the kind of stuff that gets pushed back to the browser when an error is handled by this OnPageError() method, it's a simple '|' seperated string.

If you wish to get your handler to work in the Global.asax file again, you must add some kind of <customErrors> redirect page - this drives the execution flow differently through the PageRequestManager object and leaves the error information together for your global error handler(s).


kick it on DotNetKicks.com
Friday, March 09, 2007 2:48:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Under the Hood

I haven't done a whole lot with the now ASP.Net AJAX since it was "Atlas" back in the day; and so I had forgotten a few things I knew a the time. When adding ASP.Net AJAX to your projects, remember to include within the web.config file of your main application all of the templated configuration settings found in the web.config file installed with the AJAX Extensions.

You can find this web.config file here:

%ProgramFiles%\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

Basically just snag from it all of the sections and import them into your web.config file. It seems a bit archaic, yes, but that's what you have to do in order to setup all of the HTTP Modules and whatnot needed by the AJAX runtime.

....I couldn't find any kind of wizard in Visual Studio to do this automagically. If you find one, let me know.


kick it on DotNetKicks.com
Friday, March 09, 2007 10:14:46 AM (Central Standard Time, UTC-06:00)  #    Comments [1] - Trackback
Ranting | Short and Simple
 Wednesday, March 07, 2007

Older content from my old blog IBenRush has been preserved below. New stuff soon to follow.


kick it on DotNetKicks.com
Wednesday, March 07, 2007 7:49:22 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback

 Tuesday, July 04, 2006

The June CTP of "Atlas" is out; I'd recommend downloading it if you're into that sort of thing.

The biggest change in the release is that you now have the ability to dynamically create and use UpdatePanel controls - this opens up the capability to use them in templated scenarios such as in GridViews, DataGrids, Repeaters, etc. The change the CTP made wasn't to "add" dynamic UpdatePanel controls, but to relax a constraint which pinched when Triggers had to reference the UpdatePanel.

Triggers are the feature of UpdatePanels which allows them to be connected to controls outside their content template region; that is, if the UpdatePanel surrounds a bunch of controls, but wants to also be "notified" when a control outside itself causes a post back, then it must use a Trigger (out of the box there are two types of triggers: those which update a panel when a control raises an event, and those which update a panel when a control's value changes). This is useful if you have a region that surrounds controls that must be asynchronously updated in the browser, but the control that causes the asynchronous update is  off somewhere else on the page (such as a submit button, et al).

When the client "fires" the trigger, the posted data comes back asynchronously and is retrieved/analyzed on the server during the load post data event in the page's lifecycle - which just so happens to occur before the Load, PreRender, etc. events. When the posted data is recieved on the server, the code immediately attempts to link the posted data of the trigger to an UpdatePanel in memory. But - for many controls that support templates - this is too early for an UpdatePanel control which resides within them to have been instantiated. Therefore - no UpdatePanel is found and the post back results in no change on the client....this is the constraint that was changed.

Now, as of the June CTP, you can add UpdatePanel's dynamically to a page - which means they can be inserted at any time and can therefore be a part of the template of GridViews, etc. The most blatant change which powers this new ability occured in the RegisterUpdatePanel public method of the ScriptManager object - a method called by the OnInit method of the UpdatePanel to register itself with the ScriptManager. Whenever the UpdatePanel is instantiated on the page it must register itself with the ScriptManager so that post back events can be filtered to it proxy the ScriptManager (recall that the ScriptManager is basically the king of all controls on the page). What changed in this method is that it now references two variables which are set during the load post data phase of the page lifecycle by the ScriptManager as a "this is what happened during that phase" diary for UpdatePanels that may come about later.

The first of the two new variables referenced in the RegisterUpdatePanel method stores the unique identifier for the UpdatePanel sent to it by the client if that panel isn't found by the time the load post data event occurs. The second is a boolean flag which gets set to True when the load post data phase has completed to prevent duplicate operations on the control (double initializations). Here is the code:

public void RegisterUpdatePanel(UpdatePanel panel)
{
   if (panel == null)
   {
      throw new ArgumentNullException("panel");
   }
   if ((this._allUpdatePanels != null) && this._allUpdatePanels.Contains(panel))
   {
      throw new ArgumentException("This UpdatePanel has already been registered.", "panel");   
   }
   if (this._allUpdatePanels == null)
   {
      this._allUpdatePanels = new List<UpdatePanel>();
   }
   this._allUpdatePanels.Add(panel);
   if ((this._updatePanelRequiresUpdate != null) && (panel.UniqueID == this._updatePanelRequiresUpdate))
   {
      if (panel.Mode == UpdatePanelMode.Conditional)
      {
         panel.Update();
      }   
      this._updatePanelRequiresUpdate = null;
   }
   if (this._panelsInitialized)
   {
      panel.Initialize();
   }
}

When the load post data phase has completed, and the update panel which caused the post back event on the client wasn't found, the _updatePanelRequiresUpdate variable is set to the unique id - in addition the _panelsInitialized boolean is set to true. When an UpdatePanel is instantiated dynamically at a later time, its OnInit method will be called by the page framework (when you add a control to a control collection, one of the operations done to the control is to have its OnInit method called since it wasn't around when the whole page trickled the event down to its child controls). The UpdatePanel's OnInit method calls RegisterUpdatePanel, which now has the unique identifier of the newly instantiated panel control to check against the _updatePanelRequiresUpdate variable. If the identifiers match and this new control's mode is conditional, then the panel is explicitly updated. Regardless, if the Initialize method was called for all early panel's on the page already, then the newly instantiated control has it's Initialize method called thanks to the _panelsInitialized boolean.

As a result...dynamically created UpdatePanels are now possible.


kick it on DotNetKicks.com
Tuesday, July 04, 2006 11:14:13 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing
 Monday, June 26, 2006

Okay - so I lied - one more post before I take a walk.

Check this out: http://msdn.microsoft.com/winfx/.

WinFX, right? No. .Net 3.0. Huh?

Okay - all I'm saying is that I want Indigo back; I actually liked the name Indigo, especially in comparison to the prolix "Windows Communication Foundation". I want Indigo. I also loved the name Avalon. Longhorn? Not so much - I think Vista sounds better. But doesn't Vista, Indigo and Avalon go well together? WinFX was cool to say too. Why are they trashing these cool names and giving them corporate sounding, winded names?

Perhaps I should make a button or web banner that says, "I miss Indigo". I wonder if it's because they believe it'll be more palatable by the corporate nimrods? But - seriously, what does Windows Communication Foundation give us if I'm seeing "WCF" everywhere anyway?

 


kick it on DotNetKicks.com
Monday, June 26, 2006 12:48:54 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing | Ranting

I just got a new book the other day called, "the Pragmatic Programmer" and I'm looking forward to diving into it when I get my article submitted. The fundamental idea behind the book, from what I can tell, is how to make yourself a practical developer of software - yes, that's right: a pragmatic programmer (go figure, eh!?). I believe many developers I encounter are not pragmatic (or pragmatic enough). Why? I believe it's about ego - though I'm not sure. I haven't read a damn bit of the book yet (and may I say *damn* again, because quite frankly I wish I would have more time to do so), but I will be posting thoughts as I read through it.

It's a beautiful night. I think I'm going to take a walk and hit the sack...the voices in my head are speaking in XPath expressions.  


kick it on DotNetKicks.com
Monday, June 26, 2006 12:38:25 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
Computing
 Saturday, June 24, 2006

Okay, completely off topic from what I normally write about; but I had a chance to think today (yes, frightening isn't it?) while driving 60 miles home. As I was entering Lincoln, I noticed a black squirrel and it reminded me of a friend of mine who had one living in his tree a few years back that had a white ring around its tail. It was a very weird looking squirrel. I thought to myself, "Isn't it weird how its genetics not only made it black and white, but also made the pattern rather symmetrical and neatly placed at the end of his tail?" In my usual state of way-too-much-reflection I also realized that I, too, was the product of genetics and, in an odd way, what was going on was genetics appreciating the result of genetics (me appreciating the form of the squirrel).

I took it another step further and realized that, actually, genetics is a product of the laws of nature - and that I was nature appreciating nature - which is true in an odd, contrived fashion. The premise here is that when we look on nature and on the laws of things and notice how fascinating they are because they behave in certain ways, realize that our appreciation may simply be the result of the same thing which makes nature that way.

So, we look outside and appreciate the symmetry of, say, a snowflake; but what IS the the symmetry of the snowflake IS ALSO the producer of our appreciation of that same symmetry. Why is this important? To me this shaves away a bit of the mysiticism in regards to nature - the whole "there must be a creator for these things to happen" is somewhat nullified. The argument becomes somewhat cyclical.


kick it on DotNetKicks.com
Saturday, June 24, 2006 3:10:21 PM (Central Standard Time, UTC-06:00)  #    Comments [1] - Trackback
Personal Adventures | Ranting

Computers Blogs - Blog Top Sites

Archive
<March 2007>
SunMonTueWedThuFriSat
25262728123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)