views:

50

answers:

2

i added ascx control in tab control with C# codes. if you click any tabs. ASCX control load. tab control in update pane. Alos ASCX control includes button if you click button you can add some value to database but ASCX disappear. i think that it is reloaded. How can i solve it? i loaded ascx control if i click tab control. i have a button on ASCX. i clicked button ASCX disapper..

 

    protected void ASPxPageControl1_ActiveTabChanged(object source, 
        DevExpress.Web.ASPxTabControl.TabControlEventArgs e)
    {

        if (ASPxPageControl1.ActiveTabPage.Name == "Ali Sp. Reqs")
                PhAliSpReqs.Controls.Add(UserControlHelper.LoadControl(this.Page, "~/EngWebUserControl/AliSpReqs.ascx"));
        else if (ASPxPageControl1.ActiveTabPage.Name == "Test")
                PhTest.Controls.Add(UserControlHelper.LoadControl(this.Page, "~/EngWebUserControl/Test.ascx"));

ASCX:

public partial class Test : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void Button1_Click(object sender, EventArgs e)
    {
        if (txtTest.Text != String.Empty)
        {
            Label1.Text = "Hello!";
        }
        else
            Label1.Text = "Error";
    }
}

if i clicked tab EVERY THING IS GOOD. But click button on ascx. ASCx control disappear. How can i solve it!!!

A: 

Dynamically added controls have no object reference variable in the codebehind class. They appear only in the control collection of the containing control, i.e. the Page.Controls collection. When the page is posted back to the server as a result of user interaction a new instance of the codebehind class is instantiated, and all the variables of the class is set with values from the ViewState. see here

ArsenMkrt
i don't understand?
Phsika
see edited post
ArsenMkrt
No i didn't....
Phsika
A: 

If you add controls programmatically in code, every post-back operation needs to re-create the same controls (e.g. during Page_Load) to process the post-back event (in your case, the Save button)

devio
i rearraged my codes. How can solve it. please help me!!!
Phsika
In your code, LoadControl() is only called on ActiveTabChanged to add the control. But this information does not survive postback.
devio