Unable to modify controls in an Accordion Pane on Page_Load

Last post 07-23-2007 3:42 AM by PowerSlave.ca. 5 replies.

Sort Posts:

  • Unable to modify controls in an Accordion Pane on Page_Load

    11-09-2006, 6:21 PM
    • Loading...
    • Jedly
    • Joined on 11-09-2006, 10:46 PM
    • Posts 3

    (I am using all the latest updates - completely removed everything I had and downloaded fresh stuff on November 7th) 

    If I try an make any changes to a control that is contained inside an Accordion Pane on execution of Page_Load I get the following error:

    Object reference not set to an instance of an object.

    The controls inside the Accordion Pane are fine if I don't do anything with them at Page_Load - Any events after this (such as button clicks, index changes etc) work fine.

    To simplify things I have modified the Accordion sample that comes as part of the sample web site

    To the first Accordion Pane I have added just a text box:

         <ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server">

         <Header><a href="" onclick="return false;" class="accordionLink">1. Accordion</a></Header>

         <Content>

         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

         The Accordion is a web control that allows you to provide multiple panes and display them one at a time.

         It is like having several

    <asp:HyperLink ID="CPLink1" runat="server" NavigateUrl="~/CollapsiblePanel/CollapsiblePanel.aspx" Text="CollapsiblePanels" /> where

         only one can be expanded at a time. The Accordion is implemented as a web control that contains AccordionPane

         web controls. Each AccordionPane control has a template for its Header and its Content. We keep track of the

         selected pane so it stays visible across postbacks.

         </Content>

         </ajaxToolkit:AccordionPane>

    And Page_Load is modified thus:

         protected void Page_Load(object sender, EventArgs e)

         {

         TextBox1.Text = "test";

         }

    If I was to comment this Page_Load bit, the Accordion works fine and the text box appears OK:

    If someone can confirm that this is a bug in the Accordion, then I can work around for the time being (I won't initialise at Page_Load), I will continue development and resolve in a later release.

    Alternatively, if this is for some reason by design, then I'll need to reconsider the way I am using the page and what controls I use as I ultimately need this at page load - but I am sure it is a bug as the control is on the page and should be visible to the Page Load event

    Thanks for lookin!

     

  • Re: Unable to modify controls in an Accordion Pane on Page_Load

    11-09-2006, 10:50 PM
    • Loading...
    • Jedly
    • Joined on 11-09-2006, 10:46 PM
    • Posts 3

    Further to my first post, I did come up with a workaround - I added an asp:Timer control:

     <asp:Timer id="timer_runOnce" runat="server" Interval="1" OnTick="timer_runOnce_Tick" />

    And then in my C# code added a function thus:

    protected void timer_runOnce_Tick( object sender, EventArgs e )

    {

    TextBox1.Text = "test";

    /// disable timer so it only runs once

    timer_runOnce.Enabled = false;

    }

    Note: I found this worked in my own code but not so well in the accordion example - it kept repeating - I think it had something to do with the interval and also UpdatePanels - I was using it in an UpdatePanel in my code and it worked OK. Increasing the interval helped in the Sample Accordion script.

     

  • Re: Unable to modify controls in an Accordion Pane on Page_Load

    11-13-2006, 7:15 AM
    • Loading...
    • be796801
    • Joined on 11-13-2006, 12:08 PM
    • Posts 1

    Hi,

    had the same issue and found a working workaround. The problem is thet the controls inside the accordion are not instantiated yet in the Page_Load. So I tried to find a way to have them instantiated.

    I found that if I look for a control in one of the panes, all the controls are instantiated at that time.

    So foreach accordionpane that has controls on it find a control using the FindControl method. In my case I searched for a Label and set the text of the control to a dummy 'dash' value.

    ((Label)AccordionPane1.FindControl("lblLastName")).Text = "-";

    ((Label)AccordionPane2.FindControl("lblDomain")).Text = "-";

    ((Label)AccordionPane3.FindControl("lblServer")).Text = "-";

     

    Once you searched for one control the way I did above, all the other controls are also instantiated and you can continue to set their values as before like

    lblFirstName.Text = "Dirk"; 

     

    Best regards,

     

    Dirk

  • Re: Unable to modify controls in an Accordion Pane on Page_Load

    11-13-2006, 5:19 PM
    • Loading...
    • Jedly
    • Joined on 11-09-2006, 10:46 PM
    • Posts 3

    Thanks Dirk,

    I tried that and it works a treat for me too - very clever - and neater than my timer solution

    Cheers

    Jed

  • Re: Unable to modify controls in an Accordion Pane on Page_Load

    11-13-2006, 5:19 PM
    • Loading...
    • John Grieb
    • Joined on 09-21-2005, 11:05 PM
    • New York
    • Posts 25

    An alternative way to do it is to add your initilzation code to the rest of AJAX's initialization code using the method Sys.Appication.add_init().

    When your code is executed it will be assured that the accordion conrol is loaded and initialized.

    I put the following code inline within my page and it worked fine.

    Sys.Application.add_init(

    function() {
        var behavior = $find("ctl00_mainCopy_MyAccordion_AccordionExtender");
        if (behavior)
        {
            behavior.set_FadeTransitions(
    true);
            size = AjaxControlToolkit.AutoSize.Fill;
            behavior.set_AutoSize(size);
        }
    });

     

  • Re: Unable to modify controls in an Accordion Pane on Page_Load

    07-23-2007, 3:42 AM

    I found another solution here .. http://couldbedone.blogspot.com/2007/07/what-wrong-with-accordion-control.html

    It is very elegant and simple.

    Basically, add Accordion1.FindControl("nothing") to the page_init ... controls are then accessible. Details in link.

     

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter