[CLOSED] [1.0] Javascript error when loading usercontrol from code

Page 2 of 2 FirstFirst 12
  1. #11
    I made an additional save button in the default. aspx

    default.aspx
       <ext:Button ID="det_tobbtnsave2" runat="server" Icon="Disk">
            <DirectEvents>
                <Click OnEvent="det_tobbtnsave2_Click" Timeout="300000">
                    <EventMask ShowMask="true" />
                </Click>
            </DirectEvents>
      
            <ToolTips>
                <ext:ToolTip ID="ToolTip1" runat="server" Html="Click on Save Button to find usercontrol" />
            </ToolTips>
        </ext:Button>
    and added a sub in
    default.aspx.vb
       Public Sub det_tobbtnsave2_Click(ByVal sender As Object, ByVal e As Ext.Net.DirectEventArgs)
            Dim ctrl As Control
            ctrl = FindControl("wuc_deteg001")
        End Sub
    and the result of ctrl is NOTHING

    Klaus
  2. #12
    Hi,

    The user control must be recteated for each request as any ASP.NET dynamic control
    It is ASP.NET requirement

    Please see
    http://weblogs.asp.net/infinitiesloo...t-1_2900_.aspx
    http://support.microsoft.com/kb/317794
  3. #13
    Thanks Vladimir,
    I understood that I have to recreate the usercontrol for each request.
    What I want is that the user can switch between some usercontrols and edit the data.

    So I have to load all usercontrols and add them to the controls list of the panel during the first page load (not ispostback) and recreate the usercontrol that the user is working with during postback.

    Everything worked fine with only one usercontrol, but when I load all usercontrols (with fitlayout) on first page load the page is displayed empty. All usercontrols are in the source of the page.

    I made a small sample application (VS 2010). The app is not very pretty but this is my test application for switching usercontrols.
    It seems that the page is not rendered optimal.
    Can you help me?
  4. #14
    Hi,

    Only one user control (which has layout wrapper) can be added to the container because container can work with one layout only
    Why do you load all user controls during initial page load? You have to recreate it after first creation only. I don't think that it is required to create all controls at once (during initial page load)
  5. #15
    Hi,

    to recreate a dynamicly loaded usercontrol it must be once created during initial page load.
    Otherwise the usercontrol will not be found by FindControl (I tested it!).
    If I want to give the user the possibility to switch between different usercontrols I must load all these usercontrols in "not ispostback page_load". After that all usercontrols are in the control tree of the panel and I only recreate the usercontrol the user is working with during postback.

    My workaround at the moment is that I removed the fitlayout in one of the two usercontrols.
    In the future I need more than 2 usercontrols to display and edit data.
    If you say it is possible to load only one usercontrol into a panels control tree the dynamic usercontrol are nonsense for me!

    Greetings from sunny Germany,
    Klaus
  6. #16
    I think I found a solution for this problem.
    ASP.NET needs a complete controls tree to find controls and handle the controls.
    All the initialy loaded usercontrols should not been displayed and rendered by the browser.
    So the conrols must be removed after creating of the control tree.

    http://msdn.microsoft.com/en-us/libr...fecycle_events

    The SaveStateComplete seems to be a good place:

        Private Sub default_SaveStateComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SaveStateComplete
            If Not IsPostBack Then
                det_pnlCenter.ContentControls.Clear()
            End If
        End Sub
    I will try it tonight and publish my test-project (My test-project is now at home).
    Klaus
  7. #17
    Hi,

    I will try to modify your sample to demonstrate that user controls must be recreated only after first creation (it is not required to create all possible controls during initial page load). I will post sample today

    If you say it is possible to load only one usercontrol into a panels control tree the dynamic usercontrol are nonsense for me!
    If user control inside layout then only one user control is possible because it is nonesence to have several layouts inside container (can be one UI (controls position/size) strategy only). If user control without layout then you can add several user controls
  8. #18
    My solution now works fine.
    In this sample two usercontrols (with fitlayout) can be created dynamically and processed by codebehind.
    The code is now lightly optimized.

    Klaus
    Attached Files
Page 2 of 2 FirstFirst 12

Similar Threads

  1. [CLOSED] Loading UserControl window from Parent Form throwing error
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 10, 2011, 3:43 PM
  2. Replies: 2
    Last Post: Jan 14, 2011, 5:51 PM
  3. [CLOSED] Error: 'dom.style' by loading UserControl
    By smart+ in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 30, 2010, 6:24 PM
  4. [CLOSED] Javascript error when using this usercontrol
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 25
    Last Post: Jun 15, 2010, 5:26 PM
  5. [CLOSED] Javascript Error loading dynamic usercontrol 1.0
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 01, 2010, 3:05 AM

Posting Permissions