Dynamically loaded user controls not generated events

2 posts, 0 answers
  1. Paul
    Paul avatar
    55 posts
    Member since:
    Nov 2010

    Posted 23 Apr 2015 Link to this post

    I am deciding whether to use the Telerik controls for a project. The problem I've got is fairly straightforward and I've tried to create an ultra simple test code to see if it works and it doesn't.

    I have a page with various forms of user input. I want a panel that displays a list of dynamically loaded user controls based on the user input.

    For my test page I have simply created 3 user controls: control_a, control_b and control_c

    On the main page I have a text input box and a "submit" button. I also have a xmlhttppanel and that simply has a placeholder in it The submit_click event simply reads .text property of the text box and does:

    foreach (char c in txt_input.Text) {
                if ("abc".Contains(c))
        {
    s = (UserControl)Page.LoadControl(string.Format("~/test/control_{0}.ascx", c));
    s.ID = string.Format("asynccontrol_{0}", i++);
    ph_panel.Controls.Add(s);
    } } 

    This works. It dynamically loads a set of user controls based on the user input.

    However, in control_a I have a label, a text box and a "save" button. The save_click event simply copies the text box text to the label.text

    Without using the rad control xmlhttppanel I was having a problem with a standard .net form that the dynamically loaded user controls weren't persisting. The rad xmlhttppanel appears to solve this (fab). However, the save_click event isn't executing. What have I missed?

    Do I need to do anything else to make this app run safely and robustly?

  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 28 Apr 2015 Link to this post

    Hi Paul,

    The RadXmlHttpPanel control uses client callbacks and web services which offers a performance gain over the AJAX partial updates (UpdatePanels), however it leads to having no view state and a limited page life cycle (you can find more detailed information in the following help article: http://www.telerik.com/help/aspnet-ajax/xmlhttppanel-vs-radajaxpanel.html).

    That being said, it is strange that the persistence issues you encountered previously no longer happen when there is no view state. I am guessing that the limited page life cycle is the reason why the click event is not raised.

    Overall, when your scenario involves the dynamic creation of more complex elements, it is recommended to use UpdatePanels. If you tried them and the state of the controls was not persisted, you need to ensure the following:
    - The controls are loaded on each page load.
    - The ID of the controls is not changed between postbacks, otherwise they will be detected as different controls when the state is applied.
    - View state is enabled for the page: https://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate%28v=vs.110%29.aspx



    Regards,

    Slav
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top