views:

127

answers:

1

I have an ASP.NET user control that is used in another use control. The parent user control uses data-binding to bind to a custom property of the child user control.

What method can I override or page event where I am ensured that the property state is set?

I think in a page it is PageLoaded versus the Page_Load override? I am looking for this in the user control because my property is always null even though it is set.

Thanks.

Example. This is in my user control. FilterEntryId is being bound from inside another user control:

protected int _filterEntry = -1;
    public int FilterEntryId
    {
        get
        {
            return _filterEntry;
        }
        set
        {
            _filterEntry = value;
        }
    }


    protected void Page_Load(dobject sender, EventArgs e)
    {
        FilterEntry always -1!!
    }

The property is being set but never has value when Page_Load. The Page_LoadComplete may be the proper place but does not seem to be an option in user control. I've also tried Page_DataBind.

My hypothesis is that this is a page lifecycle issue but it may be something else.

A: 

Not sure what you need to do with that property but since you can't be sure when will be set. Can't you add your logic on the set of the property?

Another option would be a later event as PreRender.

public int FilterEntryId
    {
        get
        {
            return _filterEntry;
        }
        set
        {
            _filterEntry = value;
             //HERE YOUR LOGIC
        }
    }
Claudio Redi
@Claudio yes I just thought of that! thanks.
Curtis White
@Claudio Uhm but wait.. that wont work because I need the page to do EITHER 1 thing or the OTHER thing. So, I need to know at some point. I guess I could add an extra property.
Curtis White
@Claudio Maybe I need a databound property? Something special about that
Curtis White
@Claudio the solution is prerender. I had tried that but I was looking for it to flip back and forth between the property set and the pre-render but it ran through all the property sets. Now I see! Its a friday.
Curtis White