On Sam Ng's Blog there is an article about a new feature in C#4.0: Named arguments, optional arguments, and default values
Friday, March 6, 2009
Wednesday, March 4, 2009
Test your website in mulitple browsers
On this blog there are some links for starting several browsers without installing them really on your system.
So you can easily test if your web site works well in the different versions of for example IE.
Serialization in ASP.NET
Serialization...it's difficult... but maybe with these links it makes it easier to use and not avoid. This blog provide some information about serialization. Also there is a link available to some FAQ's
Friday, February 27, 2009
Usage of keyword module?
During looking in the VB.NET code of my new Job I saw sometimes the keyword module. This keyword doesnot exist in C#.NET. The meaning of this keyword is the same as a class only all the members and methods are default shared. So the developer can become lazy;)
So my advise is to minimize the usage of the keyword module and use always the keyword class.
Friday, February 20, 2009
Some introduction links for Unity
From an previous colleague I have received the following links with some information about unity:
Reageer op externe events in plaats van zelf de touwtjes in de hand te houden. or the English variant “Don’t call us we will call you”
Thursday, February 19, 2009
How to nest web user controls dynamically?
When you use nested Web User Controls and you load them with the LoadControl method, add these controls in PlaceHolder.Controls collection (or other controls except the Page class)
Example code
wucMain.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
wucSub lMain = (wucSub)Page.LoadControl("Windows/wucSub.ascx");
Controls.Add(lMain);
}
wucMain.aspx
<strong>Main</strong><br /><asp:ListBox runat="server" ID="lstItems" />
wucSub.aspx.cs
no code behind
wucSub.aspx
<strong>Main</strong><br /><asp:ListBox runat="server" ID="lstItems" />
Test.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
wucMain1 lMain = (wucMain1)Page.LoadControl("Windows/wucMain.ascx");
Controls.Add(lMain);
}
Test.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
When you build and run these pages, you will get the following error message
"Control 'ctl02_lstItems' of type 'ListBox' must be placed inside a form tag with runat=server."
How can you solve this?
Do not use Page.Controls.Add or Controls.Addd but specify to which Controls collection these these controls must be added and use there a PlaceHolder (panel or other control). So the correct implemention will be
wucMain.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
wucSub lMain = (wucSub)Page.LoadControl("Windows/wucSub.ascx");
plhSub.Controls.Add(lMain);
}
wucMain.aspx
<strong>Main</strong><br /><asp:ListBox runat="server" ID="lstItems" /><asp:PlaceHolder runat="server" ID="plhSub" />
wucSub.aspx.cs
no code behind
wucSub.aspx
<strong>Main</strong><br /><asp:ListBox runat="server" ID="lstItems" />
Test.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
wucMain1 lMain = (wucMain1)Page.LoadControl("Windows/wucMain.ascx");
plhMain.Controls.Add(lMain);
}
Test.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder runat="server" ID="plhMain" />
</div>
</form>
</body>
</html>