locked
Save a closing Accordion Pane's data in my DB RRS feed

  • Question

  • User-1584966891 posted

    Hi

    I'm using an Ajax Accordion and what I want to do is when a panel is closed (by opening another panel) I want to save the closing panel's data in a SQL table.  So far I've been unable to find how to do this online.  I don't want to stick a save button on each panel or the page if I can help it.  I'd prefer the saving to happen without the user explicitly initiating it.

    Thanks

    FSR

    Monday, August 4, 2014 10:40 AM

Answers

  • User-1584966891 posted

    Thanks for your reply Kevin.

    I assume with your suggested solution. the user is required to click the new button, which you can't guarantee they will.

    n.b. One thing I didn't make clear, although you may have guessed it, was the panes are capturing user input, hence the reason to save it when that pane is closed. 

    For others with a similar requirement to mine, this is what I have gone with for my solution:

    Javascript:

        function pageLoad() {

            var acordionExt = $find('Accordion1_AccordionExtender');

            acordionExt.add_selectedIndexChanged(PaneChanged);

        }

     

        function PaneChanged(sender, args) {

            __doPostBack('__Page', args.get_oldIndex());

        }

    C#:

        protected void Page_Load(object sender, EventArgs e)

        {

            if (Page.IsPostBack)

            {

                string parameter = Request["__EVENTARGUMENT"];

                if (parameter != "")

                {

                    SaveClosingPane(parameter);

                }

            }

            else

            {

                //load accordion panes from db

            }

        }

     

        private void SaveClosingPane(string Pane)

        {

            //open connection

     

            switch (Pane)

            {

                case "0":

                    //do updates for first panel

                    break;

                case "1":

                    // do updates for second panel

                    break;

            }

     

            connection.Close();

        }

     

     

     

     

     

     

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 5, 2014 9:17 AM

All replies

  • User1918509225 posted

    Hi DunnoWannaNo,

    As far as I know ,you can not capture the event when you  change from one  panel  to another panel And  Save the data into the table.

     

    I suggest that you can add a new button in your page, in the button ,you can loop the Ajax Accordion control.

    Save all the data into database.

    protected void Button1_Click(object sender, EventArgs e)
    
            {
    
                foreach (AccordionPane accPane in Accordion1.Panes)
    
                {
    
                //get the header text
    
                    LiteralControl headerText = (LiteralControl)accPane.HeaderContainer.Controls[0];
    
                    string header = headerText.Text;
    
     
    
                 //get the context text
    
                    LiteralControl contentText = (LiteralControl)accPane.ContentContainer.Controls[0];
    
                    string content = contentText.Text;
    
            
    
                  //you can save the data into the table.
    
                }
    
            }
    

    Best Regards,

    Kevin Shen.

    Monday, August 4, 2014 10:48 PM
  • User-1584966891 posted

    Thanks for your reply Kevin.

    I assume with your suggested solution. the user is required to click the new button, which you can't guarantee they will.

    n.b. One thing I didn't make clear, although you may have guessed it, was the panes are capturing user input, hence the reason to save it when that pane is closed. 

    For others with a similar requirement to mine, this is what I have gone with for my solution:

    Javascript:

        function pageLoad() {

            var acordionExt = $find('Accordion1_AccordionExtender');

            acordionExt.add_selectedIndexChanged(PaneChanged);

        }

     

        function PaneChanged(sender, args) {

            __doPostBack('__Page', args.get_oldIndex());

        }

    C#:

        protected void Page_Load(object sender, EventArgs e)

        {

            if (Page.IsPostBack)

            {

                string parameter = Request["__EVENTARGUMENT"];

                if (parameter != "")

                {

                    SaveClosingPane(parameter);

                }

            }

            else

            {

                //load accordion panes from db

            }

        }

     

        private void SaveClosingPane(string Pane)

        {

            //open connection

     

            switch (Pane)

            {

                case "0":

                    //do updates for first panel

                    break;

                case "1":

                    // do updates for second panel

                    break;

            }

     

            connection.Close();

        }

     

     

     

     

     

     

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 5, 2014 9:17 AM