locked
Runtime Accordianpane goes off once button is clicked RRS feed

  • Question

  • User635582750 posted

    Hi All,

    I am using Accordion Control in my ASP.net a Questionaire Application (VS2010), I have drop this control on webform and from codebeind is generate the pane and generate the some controls at runtime, the code is show below.

    protected void EmpQuestions_GV_SelectedIndexChanged(object sender, EventArgs e)

    {

        myFunction("E001", "T001");

    }

    private void myFunction(string EId, string AnotherId)

        {

           AppDs=MyClass.GetQuetionaire(Eid,AnotherId)

    if (AppDs!=null)

    {

            AjaxControlToolkit.AccordionPane Pane = new AjaxControlToolkit.AccordionPane();

        Label lblHeader = new Label();

            lblHeader.ID ="lblHeader" + i.ToString();

            lblHeader.Text = AppDs.Tables[0].Rows[i]["Question"].ToString().Trim();

            lblHeader.CssClass ="header";

            Pane.ID ="accp_" + i.ToString();

            Pane.HeaderContainer.Controls.Add(lblHeader);

        TextBox TB = new TextBox();

            TB.ID ="TB_" + i.ToString();

            TB.TextMode =TextBoxMode.MultiLine;

            TB.CssClass ="TextBoxText";

            TB.Text = AppDs.Tables[0].Rows[i]["Answer"].ToString().Trim();

            Pane.ContentContainer.Controls.Add(TB);

            ImageButton Btn = new ImageButton();

            Btn.ID = i.ToString() +"_" + AppDs.Tables[0].Rows[i]["QId"].ToString().Trim() + "_" + AppDs.Tables[0].Rows[i]["EId"].ToString().Trim();

            Btn.ImageUrl ="~/Images/Save.png";

            Btn.Attributes.Add("runat", "server");

            Btn.Click +=new ImageClickEventHandler(ImageButton1_Click);

            Pane.ContentContainer.Controls.Add(Btn);

            Accordion1.Panes.Add(Pane);

        }

    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

        {

        string LblBtn = ((ImageButton)sender).ID;

        string[] Id = LblBtn.Split('_');

            Seq = Id[0].ToString();

            AppId = Id[1].ToString();

            Sid = Id[2].ToString();

        TextBox T = (TextBox)Page.FindControl("ctl00$Main$accp_" + Seq + "_content$TB_" + Seq + "");

        }

    I have a problem , when the Image button is clicked (generated at runtime) the Accordian control get lost with no panes and does not show any control, neither the click event is triggerred.

    Could you pls give me some solution where to stop this POSTBACK and regenrate this Accordion Control again.

    Thursday, April 10, 2014 3:42 AM

Answers

  • User-417640953 posted

    Hi hemantnaik,

    Thanks for your post.

    If you donot want to AccordionPane generated at runtime lost when postback.

    # one solution is set the Accordion to a updatepanel, that will make the Accordion not regenerate panes after postback.

    # other solution is regerate the same panes when postback in the page load event.

      protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack) 
                {
                    myFunction("E001", "T001");
                
                }
              
            }

    Besides, I suggest you take a look at Dynamically Load Data into Accordion Control using Code Behind Dataset.

    http://www.codeproject.com/Articles/138764/Dynamically-Load-Data-into-Accordion-Control-using

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 10, 2014 10:50 PM