views:

51

answers:

2

My Problem is
when I want to use UserControl with parameter.

it call both constructor( constructor with no parameter And constroctor with parameters)

is this normal situation??

if not, how should I construct the object.

public partial class FreeExperience : Arche.Web.UI.UserControlBase
{
    private ItemInfo itemInfo;
    public FreeExperience() : base()
    {
    }
    public FreeExperience(ItemInfo itemInfo) : this()
    {
        this.itemInfo = itemInfo;
    }

here I made simple userControl ,

and Call it like this on the another page.

<%@ Register TagPrefix="uc" TagName="FreeExperience" Src="include/FreeExperience.ascx" %>

...

<uc:FreeExperience ID="ucFreeExperience" runat="server"/>

And On the Page_load function of this webpage's CS

ucFreeExperience = new Arche.Itempage3.include.FreeExperience(itemInfo);
A: 
public FreeExperience(ItemInfo itemInfo) : this()

:this() is calling your default constructor, if there is no specific reason why you are doing so, you can remove it.

Actually, I always operate the other way around, and have constructors with little or no parameter, call a parametered constructor, providing default values.

Sdry
After Removing : this() I get same result. could you specifically explain about your way to use UC ?
sunglim
+1  A: 

Dont use constructors on user controls.

Expose properties with get/set accessors.

RPM1984