Contact
 

 Tuesday, February 08, 2005
Differences between System.Web.UI.LiteralControl and System.Web.UI.WebControls.Literal

Mike Ogden pointed out the fact that the DynamicControlsPlaceholder (DCP) does not correctly recreate System.Web.UI.LiteralControl. At first I was very perplexed because I was somehow sure that I successfully tried that before. However, I must have mixed it up with the System.Web.UI.WebControls.Literal which works without problems.

That raises the question why there are two different controls and how they differ. The major difference is that the LiteralControl does not persist the Text property in ViewState, which is why it is recreated emptily by the DCP. The Literal, however, takes a LiteralControl as a child and saves its Text in ViewState:

protected override void AddParsedSubObject(object obj)
{
    if (!(obj is LiteralControl))
    {
	throw new HttpException(
	    HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", 
	    "Literal", obj.GetType().Name.ToString()));
    }
    this.Text = ((LiteralControl) obj).Text;
}

So, if you want to use literal controls with the DynamicControlsPlaceholder make sure that you use Literal instead of LiteralControl.

ASP.NET | DynamicCtrlPlh
2/8/2005 8:40:45 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [1] 


 Wednesday, January 12, 2005
Needed permissions for the ASP.NET worker process user

Twice during the last 7 days, I had to look up the privileges, a custom user account needs when you want to run the ASP.NET worker process under. How to fix the ugly 80004005 error message is described here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secmod/html/secmod15.asp

http://support.microsoft.com/kb/317012/EN-US/

ASP.NET
1/12/2005 9:25:02 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Wednesday, October 06, 2004
Reported Vulnerability in ASP.NET

Please take a close look at the info page about a reported security issue with ASP.NET:

http://www.microsoft.com/security/incident/aspnet.mspx

Brian Goldfarb also started a new thread about it on the ASP.NET Forums:

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=711220

ASP.NET
10/6/2004 11:04:42 AM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Thursday, June 24, 2004
Excellent MSDN article on ASP.NET Viewstate

Scott Mitchell wrote an excellent MSDN article on the inner workings of the ASP.NET ViewState. That's cool because now I can answer half of the emails I receive about my DynamicControlsPlaceholder and dynamic controls samples by sending them the link to this article :)

It consolidates much of the information that is contained in numerous ASP.NET forum posts and extends Paul Wilson's ASPAlliance article.

Good job, Scott!

ASP.NET
6/24/2004 5:43:31 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Tuesday, March 30, 2004
Article on ASPAlliance about LoadControl vs LoadTemplate

While developing the HierarGrid I noticed that there are some subtle differences between loading UserControls with Page.LoadControl and Page.LoadTemplate. Without digging deeper into that I decided to add a property “TemplateControlMode” to the HierarGrid so that the developer can choose which way to load the template.

After some users asked what the "right" setting for the property is or reported exceptions that were related to choosing the "wrong" setting, I decided to take a look at the two implementations to find the differences. My new article on ASPAlliance explains what I've found.

ASP.NET | HierarGrid
3/30/2004 2:55:27 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Monday, February 02, 2004
"Behind the scenes of ASPX files"

A nice article called Behind the scenes of ASPX files by Natty Gur describes how dynamic compilation in ASP.NET works and extends the last paragraph of Dino's article The ASP.NET HTTP Runtime I wrote about a couple of months ago.

Still, I am missing an article that explains how dynamic code generation in ASP.NET works from an ASPX page with a couple of markup tags through the PageParser into a .cs file that is then compiled into a .NET assembly.

ASP.NET
2/2/2004 12:42:20 AM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Monday, December 08, 2003
Tracing HTTP requests with ieHttpHeaders

Jon points to this nice tool called ieHttpHeaders which I haven't heard of previously.

ASP.NET
12/8/2003 4:06:35 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Saturday, September 27, 2003
nGallery v1.0 Released!

That sounds pretty cool though I haven't tried it out (from Jason Alexander):

nGallery v1.0 Released!

Visit the nGallery site at http://www.ngallery.org to download!

nGallery is a FREEWARE, OPEN SOURCE implementation of a image gallery written purely in managed .NET and C#.

nGallery provides a solution to store and display your image galleries on your own Web site, as well as providing means for customizing and extending nGallery to your own personal likings.

ASP.NET
9/27/2003 3:03:07 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Wednesday, September 24, 2003
Why the CheckBoxList always has one child control

Today Ben Feist emailed me pointing out a problem with the DynamicControlsPlaceholder (DCP) and the CheckBoxList (CBL). He always receives a "Multiple controls with the same ID" exception when putting a CBL onto the placeholder.

So I took a look at the implementation of the CheckBoxList and noticed that like the DropDownList and the RadioButtonList (RBL) it is derived from ListControl which contains a ListItemCollection. This collection implements IStateManager and is saved in ViewState. So no need for the DCP to save the single ListItems. Why does it work with the RBL but not with the CBL?

Examining the RBL I noticed that when it comes to the render phase for each ListItem a RadioButton instance is created and written to the output TextWriter directly (see RBL.RenderItem for reference). So the ListItems/RadioButtons are never contained in the Controls collection which is used by the DCP. No problem for the DCP!

However the CBL works a bit differently: In the constructor a CheckBox control is created, added to the child collection (!) and stored in the internal member controlToRepeat. In the render phase for each ListItem the controlToRepeat is modified to reflect the text and checked state and then written to the output stream.

That's the problem for the DCP. At the end of the first request, it loops over the Controls collection noticing the CheckBox and persisting it. After the postback, the CBL constructor creates a new CheckBox again and then the DCP recreation algorithm restores the "same" CheckBox (ID="0" is hardcoded). This causes the duplicate control ID exception.

I wondered why the CBL constructor creates this special CheckBox and to find out I created a MyCheckBoxList with a "this.Controls.Clear()" constructor ;) That solved the duplicate ID problem. 

However, Ben pointed out that the MyCheckBoxList does not pick up the SelectedIndex and a quick look at LoadPostData and the HTML source revealed that the NamingContainer was incorrect.

To make a long story short, the CheckBox is added to the child collection so that the NamingContainer of the parent CBL is automatically prefixed to the ListItem index ("[CBLID]_0"). The RBL achieves the same thing manually in the RenderItem method (button1.ID = string.Concat(this.ClientID, "_", repeatIndex.ToString());)

Elegant but not very intuitive - I would expect to find either all ListItems in the control collection or none at all. So, if you ever wondered why the CBL always has exactly one child control no matter how many ListItems there are in your Items collection, you know now.

ASP.NET
9/24/2003 6:07:43 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 


 Monday, September 22, 2003
Article: Creating Custom Columns for the ASP.NET Datagrid

In case you haven't already noticed Marcie's article on custom DataGridColumns. It's worth taking a look at not only if you want to understand how the HierarGrid works. There, I created the so-called HierarColumn that acts as the container for the child templates and is filled during the ItemDataBound event.

Good job, Marcie!

ASP.NET
9/22/2003 3:09:53 PM (W. Europe Standard Time, UTC+01:00)  #  Comments [2] 


 Wednesday, September 10, 2003
Two excellent ASP.NET articles

For the last couple of weeks I had two MSDN article links on my desktop to read as soon as time permits. When I had two office days last week I read both of them and think that they are really excellent.

The first article by Dino Esposito is called The ASP.NET HTTP Runtime and covers the complete flow a request takes:

  1. coming into IIS
  2. handing over to the ASPNET_ISAPI extension
  3. passing it through named pipe to the worker process where managed code processing is taking place
  4. picking up a HttpApplication instance from the HttpApplicationFactory pool
  5. calling into ProcessRequest/ProcessRequestMain

The last chapter covers some basic aspects about dynamic compilation and the file structure in the "Temporary ASP.NET Files" folder.

I used the article as a guided Reflector tour through the down-level classes of the System.Web namespace by reading a bit and then checking what I've read in the source code (and vice versa).

The second article called Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code by Fritz Onion is not directly related with the first one but picks up some learnings from it. Basically, Fritz describes the typical problem that the main executing thread is waiting for an external resource causing it to be blocked thus resulting in bad scalability. He develops an async HttpHandler that starts a separate thread which does not belong to the ASP.NET thread pool. Pretty cool is the base class he provides that can be used as a replacement for System.Web.UI.Page for individual ASPX pages.

Both articles are very much worth reading.

I am still missing one aspect of ASP.NET written down in an article: dynamic code generation from ASPX markup language to C#/VB code (PageParser etc.). Does anyone know a good article covering this topic?

 

ASP.NET
9/10/2003 12:15:23 AM (W. Europe Standard Time, UTC+01:00)  #  Comments [0] 



Categories

Search

Blogroll


<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

RSS 2.0 | Atom 1.0 | CDF


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

© Copyright 2008, Denis Bauer