hi!!!!
i have problem with my dynamic control in tab panel
below is my code

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {             
            tabcontainer1_ActiveTabChanged(tabcontainer1, null);
            getcontrol();
        }
        

    }
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        if (ViewState["controsladded"] == null)
            getcontrol();
    }
    protected void tabcontainer1_ActiveTabChanged(object sender, EventArgs e)
    {

    }
    public void getcontrol()
    {
        AjaxControlToolkit.TabPanel thepanel = new AjaxControlToolkit.TabPanel();
        thepanel.ID = "tabpanel1";
        thepanel.HeaderText = "General";
        tabcontainer1.Controls.Add(thepanel);
        PlaceHolder ph1 = new PlaceHolder();
        thepanel.Controls.Add(thepanel);
        ph1.Controls.Add(new LiteralControl("<table>"));
        ph1.Controls.Add(new LiteralControl("<tr><td>"));
        TextBox t1 = new TextBox();
        t1.ID = "textbox1";
        t1.Text = "";
        ph1.Controls.Add(t1);
        ph1.Controls.Add(new LiteralControl("</td></tr>"));
        ph1.Controls.Add(new LiteralControl("<tr><td>"));
        Button b1 = new Button();
        b1.ID = "button1";
        b1.Text = "submit";
        b1.Click += new System.EventHandler(dynamicbutton_Click);
        ph1.Controls.Add(b1);
        ph1.Controls.Add(new LiteralControl("</td></tr>"));
        ph1.Controls.Add(new LiteralControl("</table>"));
        ViewState["controlsadded"] = true;
    }
    private void dynamicbutton_Click(Object sender, System.EventArgs e)
    {        
        label1.Text = ((TextBox)sender).Text;

    }

i have one button on tabpanel i just want to do on click event of button the text of textbox is assigned in label but when i debug it.it gives me error {Cannot evaluate expression because the current thread is in a stack overflow state.} pls help me out of here.

Recommended Answers

All 3 Replies

You should add dynamic controls in Page_Load or Page_Int events. You are trying to add dymic controls in LoadViewState method by caling getcontrol() method. Try to avoid it. It may cause the error.

You should add dynamic controls in Page_Load or Page_Int events. You are trying to add dymic controls in LoadViewState method by caling getcontrol() method. Try to avoid it. It may cause the error.

I will do it but it also give same error this is my code

public partial class clickeventcheck : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {             
            tabcontainer1_ActiveTabChanged(tabcontainer1, null);
            getcontrol();
        }        

    }
    protected void Page_Init(object sender,EventArgs e)
    {      
            getcontrol();
    }

    protected void tabcontainer1_ActiveTabChanged(object sender, EventArgs e)
    {

    }
    public void getcontrol()
    {
        AjaxControlToolkit.TabPanel thepanel = new AjaxControlToolkit.TabPanel();
        thepanel.ID = "tabpanel1";
        thepanel.HeaderText = "General";
        tabcontainer1.Controls.Add(thepanel);
        PlaceHolder ph1 = new PlaceHolder();
        thepanel.Controls.Add(thepanel);
        ph1.Controls.Add(new LiteralControl("<table>"));
        ph1.Controls.Add(new LiteralControl("<tr><td>"));
        TextBox t1 = new TextBox();
        t1.ID = "textbox1";
        t1.Text = "";
        ph1.Controls.Add(t1);
        ph1.Controls.Add(new LiteralControl("</td></tr>"));
        ph1.Controls.Add(new LiteralControl("<tr><td>"));
        Button b1 = new Button();
        b1.ID = "button1";
        b1.Text = "submit";
        b1.Click += new System.EventHandler(dynamicbutton_Click);
        ph1.Controls.Add(b1);
        ph1.Controls.Add(new LiteralControl("</td></tr>"));
        ph1.Controls.Add(new LiteralControl("</table>"));
        ViewState["controlsadded"] = true;
    }
    private void dynamicbutton_Click(Object sender, System.EventArgs e)
    {        
        label1.Text = ((TextBox)sender).Text;

    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.