AJAX Control Toolkit: Script Only


I previously posted about how to use the Microsoft Ajax Library in order to provide Globalization script functionality without using the ScriptManager control.  Why would you want to do this?

One issue is that Microsoft is currently working on the ASP.NET MVC framework, which will provide a way of doing web applications that is more familiar to PHP and JSP programmers.  In other words, it doesn’t use the WebForms infrastructure that has underpinned Microsoft’s whole approach to web development for the past six years.  The original promise of WebForms was to abstract web development so it looks more like traditional Windows Forms development.  In order to accomplish this, the developers at Microsoft have worked hard to abstract the underlying web technology using windows components that render html and emit client script for the developer.

But now the tide is turning, and with WPF and XAML, Microsoft’s newest technology for building desktop applications, we are seeing a transition to the development metaphors that we have become accustomed to in web development.

ASP.NET AJAX was originally developed following the WebForms paradigm.  While other AJAX frameworks provided script libraries that you needed to manipulate using client script (typically javascript), Microsoft provided their framework wrapped in controls like the ScriptManager and the UpdatePanel.  Even the Ajax Control Toolkit, the Microsoft backed opensource project that extends ASP.NET AJAX with additional controls, follows this model.

But the MVC model doesn’t follow this model.  It follows the model followed by every other vendor of web technology.

So how do ASP.NET MVC and ASP.NET AJAX come together if they follow these radically different models?  Well … the Microsoft AJAX team also provides the underlying scripts for their framework in the Microsoft Ajax Library, which can be used in JSP, PHP, or even your traditional HTML page if you are willing to do the muscle work required to hook into them.  They can also, of course, be used with the MVC framework.

The Ajax Control Toolkit now also exposes its underlying script files for general use, allowing use to get all the great ACT functionality with WebForms or a ScriptManager.  The only problem is that learning to use the library without controls to manage our state and emit our code is difficult, and there is very little online help to get you started.

Stephen Walther is now helping people through this difficulty on his blog, and it is a wonderful thing.  He has already tackled the Popup Calendar and Autocomplete.  Expect to hear more from him in the near future.  I can’t wait to see what he does next.

h/t to Bertrand Leroy’s Tales From the Evil Empire for highlighting this.

ASP.NET AJAX: Script Globalization without the ScriptManager


I just spent about four hours trying to solve a problem I’ll probably never actually encounter in the wild.  Someone posted on the asp.net forums about script globalization using ASP.NET AJAX.  This can be set up pretty easily by simply using the ScriptManager control and setting its EnableScriptGlobalization property to true.  ScriptManager takes care of importing the necessary scripts and handling all the underlying code required to make things work.

What the seeker on the forums wanted to know, however, was whether this could be accomplished without the ScriptManager.  In theory, all the ASP.NET AJAX framework scripts can be downloaded and used in a non-platform dependent manner.

Certain software problems are ubiquitous, and people tend to fall over themselves blogging and posting about them until Microsoft or some other vendor eventually either fixes the problem and it goes away.  On the other hand, there are problems in the software bestiary that are so rare that working on them is the programming equivalent of doing cryptozoology.

This was a juicy problem of that sort.  And I believe I have a solution. It basically involves redoing some of what the ScriptManager does automatically, but what the hey.

To support globalization in ecmascript, the ScriptManager basically sets a variable called __cultureInfo behind the scenes.  This is then used by various ASP.NET AJAX script methods to provide formatting information.  This is actually explained in the Microsoft documentation for the feature.

Behind the scenes, it seems clear, the ScriptManager is querying the CurrentUICulture of the current thread in order to determine the browser’s preferred language, and passing this to the __cultureInfo variable.  The trick, then, is to determine the format of the culture data passed to __cultureInfo.

Here I had to use reflection to discover that there is an internal ClientCultureInfo type in the Sys.Web.Extensions assembly.  It made sense that this was being serialized and passed to the __cultureInfo variable.  With some trial and error, I finally got the serialization correct.

To make this work, you will need to download the Ajax Framework Library, which is a collection of javascript files.  You will need to import the MicrosoftAjax.js file into your web project, and then reference it in your page, like this:

<script src=”MicrosoftAjax.js” type=”text/javascript”></script>

You will also need to create the ClientCultureInfo class for your project, and make sure that it is serializable.  I tried DataContractJsonSerializer class to do my serializing,  but had problem getting the DateTimeFormatInfo type to serialize correctly, so I finally opted to use the now obsolete JavaScriptSerializer.  Here’s what the class looks like:

    public class ClientCultureInfo



        public string name;

        public DateTimeFormatInfo dateTimeFormat;

        public NumberFormatInfo numberFormat;


        public ClientCultureInfo(CultureInfo cultureInfo)


            this.name = cultureInfo.Name;

            this.numberFormat = cultureInfo.NumberFormat;

            this.dateTimeFormat = cultureInfo.DateTimeFormat;



        public static string SerializedCulture(ClientCultureInfo info)


            JavaScriptSerializer js = new JavaScriptSerializer();

            return js.Serialize(info);





Now that we have the culture info formatted correctly, we need to be able to pass it to the client variable.  We’ll create a public property in the code-behind that is accessible from the client, and set its value in the Page.Load event handler:


        protected void Page_Load(object sender, EventArgs e)


            if (!Page.IsPostBack)


                CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture;

                ClientCultureInfo o = new ClientCultureInfo(cultureInfo);

                SerializedCulture = ClientCultureInfo.SerializedCulture(o);





        public string SerializedCulture




                ViewState[“kultur”] = value;




                if (ViewState[“kultur”] == null)

                    return string.Empty;


                    return ViewState[“kultur”].ToString();



Finally, we  need to use this code-behind property to set __cultureInfo.  Just add the following script block to your markup in order to set the current culture:


<script type="text/javascript">
    // Get the name field of the CurrentCulture object   
    var __cultureInfo = '<%= this.SerializedCulture %>';
    Sys.CultureInfo.CurrentCulture = Sys.CultureInfo._parse(__cultureInfo);


I added this to the bottom of the page.  To test whether this works, you will need to set the language property of your browser (if you are using IE, like I am).  I set mine to French for testing.  Then append the following script block below the one setting the culture above:

<script type="text/javascript">
    var currentCultureInfoObj = Sys.CultureInfo.CurrentCulture;
    var d = new Date();
    alert("Current culture is " + currentCultureInfoObj.name 
    + " and today is " 
    + d.localeFormat('dddd, dd MMMM yyyy HH:mm:ss'));  


If you encounter any problems, it is possible that the web.config file is overriding the culture information from the browser.  In that case, make sure the culture is set to “auto” in the config file, like this:



        <globalization uiCulture=auto culture=auto />


The Imp of the Perverse


No college freshman in America is able to escape his courses without encountering Kant’s Categorical Imperative in some form or other.  Drawing on a Medieval moral tradition that held that God has placed in each man’s heart, whether Catholic, pagan, or apostate, the knowledge of right and wrong, Kant held that each person has an inherent rational knowledge of the Moral Law, or the pure form of moral action, which is commonly known as the Golden Rule.  Behind the Golden Rule is, furthermore, an impulse to act according to the Moral Law which Kant dubbed the Categorical Imperative — a concept which Freud later took up and reinterpreted as an irrational force: the Super Ego.

For Kant, however, the Categorical Imperative was always a rational impulse which revealed our transcendent selves.  How, then, to explain the not infrequent impulse to not fulfill one’s duty to the Moral law?  According to Kant:

"We are not, then, to call the depravity of human nature wickedness taking the word in its strict sense as a disposition (the subjective principle of the maxims) to adopt evil as evil into our maxim as our incentives (for that is diabolical); we should rather term it the perversity of the heart, which, then, because of what follows from it, is also called an evil heart. Such a heart may coexist with a will which in general is good: it arises from the frailty of human nature, the lack of sufficient strength to follow out the principles it has chosen for itself…" — Religion Within the Limits of Reason Alone

Edgar Allan Poe made a point of exploring that which Kant would rather leave aside as pointless and empty of content.  In an 1850 short story, he wrote:

"Induction, a posteriori, would have brought phrenology to admit, as an innate and primitive principle of human action, a paradoxical something, which we may call perverseness, for want of a more characteristic term. In the sense I intend, it is, in fact, a mobile without motive, a motive not motivirt. Through its promptings we act without comprehensible object; or, if this shall be understood as a contradiction in terms, we may so far modify the proposition as to say, that through its promptings we act, for the reason that we should not.

"There lives no man who at some period has not been tormented, for example, by an earnest desire to tantalize a listener by circumlocution. The speaker is aware that he displeases; he has every intention to please, he is usually curt, precise, and clear, the most laconic and luminous language is struggling for utterance upon his tongue, it is only with difficulty that he restrains himself from giving it flow; he dreads and deprecates the anger of him whom he addresses; yet, the thought strikes him, that by certain involutions and parentheses this anger may be engendered. That single thought is enough. The impulse increases to a wish, the wish to a desire, the desire to an uncontrollable longing, and the longing (to the deep regret and mortification of the speaker, and in defiance of all consequences) is indulged.

"We have a task before us which must be speedily performed. We know that it will be ruinous to make delay… We glow, we are consumed with eagerness to commence the work, with the anticipation of whose glorious result our whole souls are on fire. It must, it shall be undertaken to-day, and yet we put it off until to-morrow, and why? There is no answer, except that we feel perverse, using the word with no comprehension of the principle." — The Imp of the Perverse

The tendency which Poe calls perversity — the tendency to say the wrong thing, to zig when one should zag, to procrastinate merely to see what will happen next — seems to be more ubiquitous in software programming than in other occupations.  I’ve known programmers who not only say things they shouldn’t, but seem to take a particular joy in doing so.  They do not simply lack an internal censor that would keep them from saying certain things, but seem to actually be possessed by some sort of Socratic daimon who eggs them on.

Yet sometimes I think it is not the programmers who are especially possessed of this imp, but simply they who are not able to mask it behind other, more acceptable, modes of behavior.   We often hear of the disgruntled chef who spits in a difficult customer’s food, or the unhygienic bartender who slips unsanitary items in a customer’s drink.  The same impulse, I think, takes over middle-managers at times.  They, who are forced to do unpleasant tasks by their direct managers, and who in the end are blamed by both the people under them as well as those over them when things go wrong, are always suspected of taking a particular pleasure — dare I say a perverse pleasure — when unpleasant things, such as dressing down an employee or on occasion firing one, must be done.  What is more perverse, after all, than actually taking pleasure in performing unpleasant tasks, and who could blame them if they did?

Similar to Poe’s "mobile without motive," Robert Herrick captured the mood as one of Delight in Disorder (1648):

A SWEET disorder in the dress
Kindles in clothes a wantonness :
A lawn about the shoulders thrown
Into a fine distraction :
An erring lace which here and there
Enthrals the crimson stomacher :
A cuff neglectful, and thereby
Ribbons to flow confusedly :
A winning wave (deserving note)
In the tempestuous petticoat :
A careless shoe-string, in whose tie
I see a wild civility :
Do more bewitch me than when art
Is too precise in every part.

The sexual element that is implicit in Herrick’s understanding of the imp of perversity is remarkably absent from Poe’s, just as the element of danger, pervasive in Poe, is absent in Herrick.  Our contemporary notion of the perverse tends to span both elements, and is generally accessorized with leather where Herrick has petticoats, and piercings where Poe envisions only murder.  Yet even in our own times perversity has started to lose some of its perverse luster.  The Christian Coalition may decry the slipping of moral standards as a slow slouching towards the Rapture, but I see the problem, rather, as one in which we’ve denied ourselves the real pleasures of perversity.  When even leather and piercings have lost their power to outrage as well as titillate, where shall we turn?

I’ve recently been enjoying pulp novels from the 40’s with a certain amount of furtive excitement that those authors are writing things they would never get away with writing today.  For instance, from Mickey Spillane’s 1948 I, The Jury (for those unfamiliar with the series, Mike Hammer is a tough detective, while Velda is his faithful secretary):

"Here’s one you’ll like, chum," Velda grinned at me.  She pulled out a full-length photo of a gorgeous blonde.  My heart jumped when I saw it.  The picture was taken at a beach, and she stood there tall and languid-looking in a white bathing suit.  Long solid legs.  A little heavier than the movie experts consider good form, but the kind that make you drool to look at.  Under the suit I could see the muscles of her stomach.  Incredibly wide shoulders for a woman, framing breasts that jutted out, seeking freedom from the restraining fabric of the suit.  Her hair looked white in the picture, but I could tell that it was a natural blonde.  Lovely, lovely yellow hair.  But her face was what got me.  I thought Velda was a good looker, but this one was even lovelier.  I felt like whistling.

"Who is she?"

"Maybe I shouldn’t tell you.  That leer on your face could get you into trouble…"

And so on and so forth.  I, The Jury was a runaway bestseller and made Mickey Spillane’s career.  This was due in no small part to the racy writing and tight plot, but something should also be said for the cover art.  Here’s the cover of the original 1948 edition:


And here’s the cover redone for a later edition:


Finally, here’s the poster art for a film version:


Do you notice a common theme?  A man with a gun pointed at a woman undressing.  Is he holding the pistol in order to force her to undress?  Or is she undressing in order to compel him to drop the pistol?  Thousands of readers in the 40’s and 50’s felt compelled to read the book in order to find out what was behind this juxtaposition of sex and violence, drawn by the imp of the perverse. 

Last of the Great Whistleblowers


Anne Applebaum has written one of the better obituaries for Alexander Solzhenitsyn in her column for the Washington Post:

"Even Solzhenitsyn’s expulsion from Russia in 1974 only increased his notoriety, as well as the impact of "The Gulag Archipelago." Though it was based on "reports, memoirs and letters by 227 witnesses," the book was not quite a straight history — obviously, Solzhenitsyn did not have access to then-secret archives — but, rather, an interpretation of history. Partly polemical, partly autobiographical, both emotional and judgmental, it aimed to show that, contrary to what many believed, the mass arrests and concentration camps were not an incidental phenomenon but an essential part of the Soviet system — and had been from the very beginning.

"Not all of this was new: Credible witnesses had reported on the growth of the Gulag and the spread of terror since the Russian Revolution. But what Solzhenitsyn produced was simply more thorough, more monumental and more detailed than anything that had preceded it. His account could not be dismissed as a single man’s experience. No one who dealt with the Soviet Union, diplomatically or intellectually, could ignore it. So threatening was the book to certain branches of the European left that Jean-Paul Sartre himself described Solzhenitsyn as a "dangerous element." Its publication certainly contributed to the recognition of "human rights" as a legitimate element of international debate and foreign policy.

"His manuscripts were read and pondered in silence, and the thought he put into them provoked his readers to think, too. In the end, his books mattered not because he was famous or notorious but because millions of Soviet citizens recognized themselves in his work: They read his books because they already knew that they were true."

It is a peculiar meme in Western Culture that, at some level, the evil of Stalin’s Soviet regime cannot be viewed on the same level as, say, Hitler’s Third Reich.  It sometimes takes the form of faint attempts to explain it away, or to see it as an aberration of the Soviet state, and generally ends in a change of subject.  This aura of lingering romanticism about the Soviet State among Westerners is odd and, I think, rather inexplicable.  A meme is probably the best way to describe it.

In Russia itself, the attitude is perhaps easier to understand.  No one likes to be reminded of their own sins, and no one likes bad news that is unlikely to gain them anything.  In her book, Gulag: A History, Applebaum describes the typical reactions of people she encounters in Russia once they discover that she is doing a historical investigation of the Gulag system.

"At first, my presence only added to their general merriment.  It is not every day one meets a real American on a rickety ferry boat in the middle of the White Sea, and the oddity amused them.  They wanted to know why I spoke Russian, what I thought of Russia, how it differs from the United States.  When I told them what I was doing in Russia, however, they grew less cheerful.  An American on a pleausre cruise, visiting the Solovetsky Islands to see the scenery and the beautiful old monastery — that was one thing.  An American visiting the Solovetsky Islands to see the remains of the concentration camp — that was something else.

"One of the men turned hostile.  ‘Why do you foreigners only care about the ugly things in our history?’ he wanted to know. ‘Why write about the Gulag?  Why not write about our achievements?  We were the first country to put a man into space!’  By ‘we’ he meant ‘we Soviets.’

"His wife attacked me as well.  ‘The Gulag isn’t relevant anymore,’ she told me.  ‘We have other troubles here.  We have unemployment, we have crime.  Why don’t you write about our real problems, instead of things that happened a long time ago?’

"In my subsequent travels around Russia, I encountered these four attitudes to my project again and again.  ‘It’s none of your business,’ and ‘it’s irrelevant’ were both common reactions.  Silence — or an absence of opinion, as evinced by a shrug of the shoulders — was probably the most frequent reaction.  But there were also people who understood why it was important to know about the past…"

This is toward the end of the book.  Just as interesting is how the book begins, with an observation on a bridge.

"Yet although they lasted as long as the Soviet Union itself, and although many millions of people passed through them, the true history of the Soviet Union’s concentration camps was, until recently, not at all well known.  By some measures, it is still not known.  Even the bare facts recited above, although by now familiar to most Western scholars of Soviet history, have not filtered into Western popular consciousness.

"I first became aware of this problem several years ago, when walking across the Charles Bridge, a major tourist attraction in what was then newly democratic Prague.  There were buskers and hustlers along the bridge, and every fifteen feet or so someone was selling precisely what one would expect to find for sale in such a postcard-perfect spot.  Paintings of appropriately pretty streets were on display, along with bargain jewelry and ‘Prague’ key chains.  Among the bric-a-brac, one could buy Soviet military paraphernalia: caps, badges, belt buckles, and little pins, the tin Lenin and Brezhnev images that Soviet schoolchildren once pinned to their uniforms.

"The sight struck me as odd.  Most of the people buying the Soviet paraphernalia were Americans and West Europeans.  All would be sickened by the thought of wearing a swastika.  None objected, however, to wearing the hammer and sickle on a T-shirt or a hat.  It was a minor observation, but sometimes, it is through just such minor observations that a cultural mood is best observed.  For here, the lesson could not have been clearer: while the symbol of one mass murder fills us with horror, the symbol of another murder makes us laugh."

I do not play the game myself, but a friend tells me that there is a similar controversy in Civilization IV concerning the presence of Stalin as a player character in this PC game and the absence of Hitler.  Here is a small flame war over it, with links to more flame wars.  Another friend, who is ethnic Chinese, resents the presence of Mao in the game.

Perhaps the greatest trick the Devil ever played, to paraphrase Kaiser Sose, was to convince people that he was Adolf Hitler, while men like Alexander Solzhenitsyn worked to convince us that things were otherwise.  To quote the man himself:

"If only there were evil people somewhere insidiously committing evil deeds, and it were necessary only to separate them from the rest of us and destroy them. But the line dividing good and evil cuts through the heart of every human being. And who is willing to destroy a piece of his own heart?”  – The Gulag Archipelago

The Quiet Mind


Like an Empiricist prescription or an occult warning, depending on how you take it, Wittgenstein wrote as a coda to the Tractatus Logico-Philosophicus,  Wovon man nicht sprechen kann, darüber muß man schweigen.  C. K. Ogden translates this as “Whereof one cannot speak, thereof one must be silent.”

I have spent the past week trying to learn how to be silent, again.  I unplugged myself from the Internet and went to the beach with my family where I spent several days trying to silence the various voices that constitute a perpetual background cacophony in my head.  The ocean swell helped me to accomplish this quiescence of the noetical Madding crowd, until finally there was nothing left but stillness in my brain and the inbreath and outbreath of the sea as it filled up the new tide pools of my mind, and a gasp escaped my lips and traveled over the waters as I realized that this really was a vacation, at last, and it wasn’t what I had expected.

This sense of quietude is what I have always taken Heidegger to be referring to when he discusses Lichtung — the clearing — in his writings, for instance in Being and Time where he writes:

“In our analysis of understanding and of the disclosedness of the “there” in general, we have alluded to the lumen naturale, and designated the disclosedness of Being-in as Dasein’s “clearing”, in which it first becomes possible to have something like sight.” — tr. Macquarrie & Robinson

Except that for me, sight is a place holder for my inner monologue, and the clearing is a place to rediscover my inner voice.  We are all social animals, after all, and when we are with other people our inner voices become drowned out by the various social pressures that sweep us along, whether this is in politics, or at work, or on the Internet, the biggest stream of voices available.  My general strategy in life is to fill my mind with so many voices that they eventually begin to cancel each other out so that my rather weak voice can have some influence within my own head.  But this doesn’t always work, and I eventually need to detox in a quiet place.

Heidegger uses a clearing in the woods as his metaphor for this place, but I think the ocean serves the purpose even better.  The ocean is a natural source of white noise, and the way white noise affects human beings is peculiar.  According to some studies, the appeal of white noise seems to be specific to primates, and to humans in particular.  According to the Aquatic Ape theory, human evolution is intimately tied to the coast, and this might explain, in a hand-waving sort of way, our affinity for the ocean and the sounds of the ocean.  It is the music that calms the inner beast.

The inner monologue is a peculiar, though pervasive, phenomenon.  An interesting observation concerning it occurs in Augustine’s Confessions.  Augustine expresses amazement at the fact that his mentor, Ambrose, is able to read without moving his lips.  This gives us a strange impression of the Roman world — apparently it has not always been the case that people read silently in an ALA approved manner.  This in turn has led various philosophers to wonder if the inner monologue existed for these Romans, or if they simply articulated everything they thought.

For Derrida, this became a motif for his philosophical studies.  In an early work, Speech and Phenomena, Derrida tries to find the source of Husserl’s phenomenological insight in The Logical Investigations, and concludes that it is due to a basic confusion between observation and speech.  Because in speech we are capable of this inner monologue, Husserl, according to Derrida, made the analogous assumption that we can exist, in some peculiar way, without the world.

“For it is not in the sonorous substance or in the physical voice, in the body of speech in the world, that he [Husserl] will recognize an original affinity with the logos in general, but in the voice phenomenologically taken, speech in its transcendental flesh, in the breath, the intentional animation that transforms the body of the word into flesh, makes of the Körper a Leib, a geistige Leiblichkeit.” — tr. David B. Allision

Just as Derrida saw in the Logical Investigations the germ of the entire Husserlian project, the Husserlian David Carr used to tell us that the germ of Derrida’s project could be found in this brief passage.  Taking the problem of authorial intent to a philosophical level, Derrida wants to cast doubt on the meaning of the inner voice, and it’s privileged status as the arbiter of the meaning of its utterances.  It is a sort of Neo-Empirical game that resembles the attacks often made by material-reductionists on the folk-psychology of consciousness, which has at its core the notion that for the most part we all know what we are talking about when we talk about something.  Instead, the inner voice is a sort of illusion to be dispelled, like witchcraft and theology.

And yet I can’t help but feel that there is something to the inner voice.  For instance what was George Bush thinking about when he was first notified about the 911 attacks?  What was Bill Clinton thinking and intending in that fateful pause between the phrases “woman” and “Monica Lewinsky” that changed the meaning of this statement (skip to end for the good bit)? 

Silence isn’t simply a turning off of the mind.  When the lights go out, we may stop seeing things, but when all noise is shut out, we continue to hear ourselves, and it is perhaps the best time to hear ourselves and in the act recollect ourselves.

I leave you with John Cage’s composition 3′ 44”, which is pregnant with the composer’s intent, as well as the performer’s in this unique rendition.