first_page

ASP.NET 1.x Revisited (again)

Abandoning the one-page application. Oh, you snickering things. You imperial, sophomoric sufferings of succotash. I can imagine (based on years of horrible experiences) what you are thinking—but yes—honestly, yes: I am aware that Microsoft does not recommend declaring a form element in ASCX files. But I tried it anyway because I am a code-slinging thug (see previous post with a new strikethrough). And, like Marcus Garvey during his first public speech in the United States, I fell flat on my face. But we don’t die: we multiply. First of all, putting a form element in a user control is not recommended because:

  • Only one form element running at the server is allowed per ASPX page. A user control with a form running at the server loading into a page that already has a form server control will raise an exception.
  • When a post-back occurs in a form control declared in an ASCX file, any child controls of this form may not catch POST data. I use the word “may” because this is what is happening on my machine. I (with Google™) can’t seem to find anyone else on Earth “stupid” enough to try to do what Microsoft does not recommend.

This last bit is little hard to explain in words but the workaround is to capture POST data directly from the Request.Form collection. However, this can get ugly because the key names in this collection are often the ‘stupid names’ ASP.NET uses to track controls running at the server. So I had to write a function to handle this problem. This is the function:public static string RequestFormElement(System.Web.UI.Control Control) { string str = Control.ClientID.Replace(String.Format("_{0}",Control.ID), String.Format(":{0}",Control.ID)); return str; }

I find this technique a bit delicate and brittle because a future “service pack” of ASP.NET 1.x (running alongside ASP.NET 4 billion) might change the naming convention on which this function relies. So I face the reality of the situation and will rely on inheritance. But I defend my attempt to achieve the “visual” inheritance pattern that ASP.NET 2.0 addresses with master pages.

rasx()