Changing the UserControl Property

advertisements

I have created a User Control(Popupcontrol) and in that control i have created a property(PageType) and when i am using the Popupcontrol on the page then i set the property(pagetype) according to the page. but now there is some problem i have to two button on the page and on the second button click i want to change the pagetype property .So is there any solution for the same.


Based on your comment, it seems you bind the data (PageType property in your question) in the Page_Load event, instead of this it should be done in overrided DataBind method which should be called if the page is not in post back request (otherwise your data will be overwritting in the next Page_Load event as you mentioned in your comments):

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack)
    {
        DataBind();
    }
}

public override void DataBind()
{
    PageType = someValue;
}

after this your click handler may looks like:

protected void button2_Clicked(object sender, EventArgs e)
{
    PageType = someOtherValue;
}