Server controls
One of the biggest waste I see in using viewstate is that it persists values that are already set in the aspx. These get set every time that the page runs and don’t need to be round tripped to the browser so that they will be persisted.
I did a little experiment a while back where [...]
Published in ASP.NET, Server controls on Sunday, February 1st, 2009
Use custom attributes to take the tedious work out of creating server control properties that persist to ViewState. Declare a normal property and use an Attribute to tag it for storage to ViewState. See how to use reflection to see which properties need to be persisted.
Published in Server controls on Wednesday, August 13th, 2008
Here’s a small plug for Joel who has just released a book on something quite dear to my heart, ASP.NET server controls. It’s called Advanced ASP.NET AJAX Server Controls for .NET Framework 3.5 and looks very interesting. I’m looking forward to adding it to my library. It’ll be nice to have an update to Nikhil’s [...]
Published in Server controls on Thursday, July 10th, 2008
One nice feature of ASP.NET 2.0 is a new interface called IButtonControl. You can use it in a code behind to say a control needs to be a button but without actually saying whether it needs to be a Button, LinkButton, ImageButton or custom control button type.
This is the type of thing that’s useful if [...]
Published in ASP.NET, Server controls on Monday, June 30th, 2008
ASP.NET smartie pants Scott Guthrie has linked to a really interesting article about supporting templated areas in ASP.NET controls. This is aimed at people doing user controls, but the same thing will work if you want to have a templated area in your own custom control.
I’ve created a little sample that shows how to do [...]
Published in Server controls on Saturday, June 10th, 2006
I found a very interesting article about ASP.NET data binding that talks about exactly what’s happening when you call the DataBind() method on a templated control like the repeater. It’s got some really interesting stuff on how the templates are instantiated and how the child controls are built.
Published in Javascript, Server controls on Monday, April 10th, 2006
I don’t know if this will be useful to anyone else but I thought this was kind of a neat trick for messing around with ASP.NET page rendering for debugging purposes.
My problem was I wanted to stop the rendering of a page at a certain point so I could see how the scripts were reacting [...]
Published in ASP.NET, Javascript, Server controls on Friday, April 7th, 2006
I ran into a weird problem with dynamically created ASP.NET 2.0 user controls yesterday. I was using the user control to populate a panel of a tab control which meant I didn’t actually have a reference to the user control object anywhere on my form. The only way I could get a reference to it [...]
Published in ASP.NET, Javascript, Server controls on Thursday, April 6th, 2006
On the subject of the ASP.NET 2.0 web resources, something very useful to know is they aren’t cached when debug is set to true in your web.config.
My research suggests that regardless of this caching isn’t enabled at all on Cassini (aka the ASP.NET development server). It doesn’t seem to even cache static files and it [...]
Published in ASP.NET, Server controls on Thursday, March 16th, 2006
ASP.NET 2.0 has a really nice feature that lets you compile site or component resources like javascript files into your assembly file instead of deploying these shared files to the wwwroot/aspnet_client directory like in ASP.NET 1.x. This makes your component/website much easier to deploy because it means you can keep everything you need in one [...]
Published in ASP.NET, Server controls on Wednesday, January 11th, 2006
I was playing around with embedded web resources and was having a problem loading some javascript files. When I cut and paste the script link from the source of my page into the browser’s address bar I got the following error message:
The resource cannot be found. Description: HTTP 404. The resource you are looking for [...]
Published in ASP.NET, Server controls on Wednesday, January 11th, 2006
Step 1:
Create a WebControl that implements the IPostBackEventHandler interface.
In my example I’ve created a CustomButton control that is a HTML <span> element that acts like a real button by trigging a postback and firing a Click event.
public class CustomButton : WebControl, IPostBackEventHandler
{
public CustomButton()
{
}
public void RaisePostBackEvent(string eventArgument)
{
}
protected override void Render(HtmlTextWriter writer) {
base.Render (writer);
writer.WriteBeginTag("span");
writer.WriteAttribute("class", this.CssClass);
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(this.Text);
writer.WriteEndTag("span");
}
private string _text;
public string [...]
Published in Server controls on Monday, October 24th, 2005