3

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);
1
  • After Removing : this() I get same result. is this normal?? Commented May 21, 2010 at 8:56

2 Answers 2

9

Dont use constructors on user controls.

Expose properties with get/set accessors.

Sign up to request clarification or add additional context in comments.

Comments

1
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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.