Emil Stoichev's Blog

Just a few coding tips

October 2007 - Posts

SilverlightShow.net Beta2 Launched!

About 2 months ago I and a few of my colleagues started a Silverlight community site with the hope to be a trustworthy source for Silverlight content and to give our visitors the best we can offer. SilverlightShow has been developed as an internal project, we cannot offer that much functionality in this short time and limited budget. With this release I think we did a good job, though. The thing I'm mostly happy about is the interviews we took from some really cool guys like Chad Hower a.k.a Kudzu (MVP, Regional Director Adviser for Microsoft MEA), Lino Tadros (MVP, CEO Falafel Software), Todd Anglin (MVP, Telerik Technical Evangelist) and Xavier Lemoine ( Netika Technical Evangelist). It is so easy to talk with these guys – they are so experienced and no matter what you ask them, they can talk for hours. I really hope you like the interviews and learn something.

This release also includes Showcase, Get Started and Event sections. With all this content – news, articles, shows (interviews), showcase and events – SilverlightShow.net now offers all you need gathered together in well organized way for you to stay tuned for Silverlight. If you are interested in this technology, I'd highly recommend you to join the community and subscribe for the feeds.

Of course there is still a lot to be done for the community and we will keep contributing and adding new features. It's just a matter of time. So stay in touch and I promise we won't disappoint you ;) We are also looking for a partnership with other communities and users ready to contribute, so send us an email at support [at] silverlightshow [dot] net if you have something on your mind.

I received a couple of emails asking what CMS we use for SilverlightShow.net. We don't use third-party CMS. As this is an ASP.NET blog I'll say a couple of things for the design of SilverlightShow.net and what problems we faced during development.

For an experienced ASP.NET developer this project is not such an interesting thing as it is almost just a CRUD (create, retrieve, update, delete) application without any complex logic. It is entirely based on something we call "a Resource item" which is the object behind news, article, show, etc. The resource item has common fields as Title, Description, Author, etc. Then if a content item has something specific, like a podcast which has a video file, a new business object that inherits ResourceItem is created with its specific properties. The object model completely reflects the database design. That approach makes it super easy to organize the data and display it.

We use a couple of third-party controls and frameworks like ASP.NET Pager – for paging result items, ELMAH for error logging, the ASP.NET AJAX Control Toolkit, ASP.NET Futures (the media control), the Argotic Syndication Framework, Subkismet – the cure for comment spam, URLRewriter.NET, etc. For the time being I'm preparing a blog about the custom controls, frameworks and tools I use in my everyday development and there I'll tell you more about them.

If you want to learn more what is behind SilverlightShow let me know.

Thoughts on the ASP.NET ViewState

Last week I've attended the DevReach conference in Sofia, Bulgaria. It is one of the few international events presented in South Eastern Europe, but a lot of famous international speakers took part in it and I would say it was a good conference. I met a number of well-known faces from the .NET community worldwide and I also had the chance to interview Lino Tadros, Chad Hower a.k.a Kudzu and Todd Anglin (big thanks guys!) for SilverlightShow.net.

One of the sessions I attended was about Tips & Tricks for Managing ViewState (by Todd Anglin). It made me acquire a deeper knowledge on this 'magic' StateBag. A lot of developers, not only junior, are confused about how the ViewState actually works. If you google about ViewState, you will find a couple of articles that explain the 'magic' – some of them good, some of them not so. I strongly recommend reading the blog of Dave Reed (Infinities Loop) TRULY Understanding ViewState if you want to truly understand it ;)

The thing in Todd Anglin's session which provoked me to blog about is the way he programmatically set control properties – in the PreInit stage. Just to give you an overview of the ViewState lifecycle, I'll say that it is loaded in the Init stage and this is exactly where TrackViewState() is called. After that, if a ViewState value is changed, it is considered dirty and StateBag.SaveViewState() will save and return the new value when its state is requested. Having this in mind you can think of changing control properties at the PreInit event. Yes, that is great place. They won't be marked as dirty because TrackViewState() is not still called.

So if you have a code like the following your ViewState won't suffer.

protected override void OnPreInit( EventArgs e )

{

litMessage.Text = "Hey, my ViewState is less than before! Ha!";

base.OnPreInit( e );

}

Just as simple as that. Then, why do we continue to see lot of ASP.NET tutorials, articles, blogs, etc. that initialize control properties at the Load event? Frequently I see code like this:

protected void Page_Load( object sender, EventArgs e )

{

if ( !IsPostBack )

{

gridData.DataSource = myDataCollection;

gridData.DataBind();

}

}

What is the size of myDataCollection? 10kb? 20kb? 120kb? Depends on the data. But why, even if it is 10bytes don't you put it in the PreInit event? Hey, when we are talking about public web applications, that matters! Notice that the next time you set default values, bind data, etc.

In case you use a MasterPage you can't use this tip. MasterPage is treated like a control in the ContentPage and all the controls on the page aren't still initialized at this stage. The simplest thing you can do is to wire up the Init event of the control and there to set the properties you want. Of course, you can use this trick even you have no MasterPage but you don't want to wire up the Init event of all 100 controls you have on the page, do you? ;)

As this is my first contribution to the ASP.NET community, I hope I've helped you guys and I'll be glad to have your feedback.

More Posts