Problem with dynamically added controls, postback and AJAX

3 posts, 0 answers
  1. Steven Bixby
    Steven Bixby avatar
    14 posts
    Member since:
    Sep 2008

    Posted 17 Mar 2016 Link to this post

    I have a page for which the ASPX consists of an empty RadMultiPage, plus a RadAjaxManager.  The RadMultiPage has a PageViewCreated handler, and the form has an asp:Timer which fires every 15 seconds to provide an auto-refresh.    The RadAjaxManager has ajax settings for the Timer object to update a label, a hidden field and the RadMultiPage.

    In the Page_Load, within if (!IsPostBack) {}, I create a new RadTab + RadPageView for each page of my display.  In turn, when the page loads, all of the controls within each page are generated via C# code based on database information.   The controls include replicated blocks, and in each block there are a pair of ImageButtons (Plus, Minus) which are to update a value within the block.

    When I create each of the two ImageButtons and the associated Label which contains the affected value, I add a handler into my code-behind, and I use RadAjaxManagerForm.AjaxSettings.AddAjaxSetting(<ImageButton>,<Label>).   I also save an Attribute to each button with the ID of the Label control so I can find it in the button Handler.

    The handler used an Attribute on the 'sender' (ImageButton) to find the ID of the associated Label to be updated, and I tried two ways -- to save the Label control in a Dictionary<string,Label> in the PageViewCreated handler, and by using sender.Parent.Parent, etc to navigate through the tree to find the Label.  Both had the same result.

    So, this sort of works for me, I can load the page, and I can click the plus/minus buttons and see the value change in the control associated with the buttons.   After a full page refresh, I can click Plus/Minus button and see a result in the Label.   I also see my value updated in the database, so it's functioned correclty so far.

    The weird part is that when the page auto-refreshes.  all of the control blocks *except* the one I used Plus/Minus buttons on -- are updated to the value from the DB.  If I change all values, then they all reflect the new values except the one I clicked on.  If I then do a full page refresh, all values update correctly, and after that, will reflect the values from the DB normally.

    So it appears that by finding the Label control in my button handler and updating it's Text, this control is now somehow locked into the ajax responses as some floating object and the underlying PageCreated handler doesn't seem to affect what the browser shows for that control.  If I *don't* update the Label in my button handler but instead wait for the page refresh, the Label will update from the database as I'd like -- but the user is confused because it takes as long as 15 seconds for the change to show.

    So, what am I doing wrong here?  I could try to create a stand-alone sample but it might take hours to extract, so first I'm hoping someone sees my error outright.


  2. Steven Bixby
    Steven Bixby avatar
    14 posts
    Member since:
    Sep 2008

    Posted 18 Mar 2016 in reply to Steven Bixby Link to this post

    I created a sample for this, hoping someone can take a look?  I'm stuck!!

  3. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 22 Mar 2016 Link to this post

    Hello Steven ,

    I handled the support ticket you have opened for the same issue. I would suggest you to continue our communication there so that we can easily track the problem.

    Maria Ilieva
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top