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

Page 1 of 2 12 LastLast
  1. #1

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

    I get an Javascript error when loading a usercontrol with Fitlayout .

    If Fitlayout is missing everything is ok.

    Static loading from ascx file is also ok.

    I made a small example.
    Last edited by geoffrey.mcgill; Jul 07, 2010 at 2:25 AM.
  2. #2

    RE: [1.0] Javascript error when loading usercontrol from code

    Hi,

    UpdateContent should be used during AjaxRequest only. Therefore wrap your LoadUserControl calling by IsAjaxRequest
     If (Ext.Net.X.IsAjaxRequest) Then
                LoadUserControl(def_pnlwuc01, "wuc01")
            End If
  3. #3

    RE: [1.0] Javascript error when loading usercontrol from code

    Hi,

    By the way, why do you need to update content on each request? Is it really required?
  4. #4

    RE: [1.0] Javascript error when loading usercontrol from code

    Thanks Vladimir

    I don't need to update the content on each request.
    The sample application only has to show the error.

    I will try to load the usercontrol in an ajaxrequest.

  5. #5
    The problem still exists also in an Ajaxrequest.
    If you delete the Fitlayout (and <Items>) from usercontrol the usercontrol can be loaded otherwise a javascript-error occurs.

    How can I use Fitlayout in an usercontrol?

    I made another small example.

    Klaus
  6. #6
    Hi,

    UpdateContent must be used if content without layout. If you wrap user control body by layout then you have to use Render method of the Container (def_pnlwuc01 panel in your case)

    def_pnlwuc01 is center region, center region cannot be rerendered because it cannot be removed from layout(Render method destroys previous instance)

    Solution:

    1. Wrap def_pnlwuc01 panel by Container with Layout="Fit"
    <ext:Container runat="server" Layout="Fit">
              <Items>
                    <ext:Panel ID="def_pnlwuc01" runat="server" Layout="Fit" Title="UserControl" Icon="ApplicationViewDetail">
    2. Use Render method instead UpdateContent
    def_pnlwuc01.Render()
  7. #7
    Hi Vladimr,

    the code work fine in my sample application but in my real application i get now another javascript error.
    If you add a store and a combobox to the usercontrol ascx file you get another javascript error (ucde01_RefCategory is undefined).
    What can I do?

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="wuc_deteg001.ascx.vb" Inherits="uc_event.wuc_deteg001" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <ext:Store ID="ucde01_RefCategory" runat="server" RemoteSort="true">
        <Reader>
            <ext:JsonReader  IDProperty="RcaId">
                <Fields>
                    <ext:RecordField Name="RcaId" />
                    <ext:RecordField Name="RcaName" />
                    <ext:RecordField Name="RcaShortname" />
                    <ext:RecordField Name="RcaForeignKey" />
                    <ext:RecordField Name="RcaSort" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    
    
      <ext:FitLayout ID="ucde01_FitLayout1" runat="server">
        <Items>
          <ext:Panel ID="ucde01_View01" runat="server" Border="false" Layout="Absolute" AutoScroll="true" TitleCollapse="true" Height="600">
                <Items>
                    <ext:TextField ID="ucde01_Txt_CusId" runat="server" X="0" Y="0" Width="20"  Hidden="true"/>
                    <ext:Label ID="ucde01_Lbl_CusNo" runat="server" X="4" Y="12" Text="Kundennummer" />
                    <ext:TextField ID="ucde01_Txt_CusNo" runat="server" X="140" Y="8" Width="240" MaxLength="20" ReadOnly="true"/>
                    <ext:Label ID="ucde01_Lbl_CusNo5" runat="server" X="4" Y="40" Text="Kundennummer alt" />
                    <ext:TextField ID="ucde01_Txt_CusNo5" runat="server" X="140" Y="36" Width="240" MaxLength="10" ReadOnly="true"/>
                    <ext:Label ID="ucde01_Lbl_CadName1" runat="server" X="4" Y="68" Text="(Firmen)name" />
                    <ext:TextField ID="ucde01_Txt_CadName1" runat="server" X="140" Y="64" Width="240" MaxLength="50" />
                     <ext:ComboBox ID="ucde01_Cmb_CusRcaId" runat="server" StoreID="ucde01_RefCategory" Width="240" TypeAhead="true" Mode="Local" ForceSelection="true" TriggerAction="All" EmptyText="Wähle Kategorie..." SelectOnFocus="true" X="544" Y="484" ValueField="RcaId"  DisplayField="RcaName" > </ext:ComboBox>    
    
               </Items>
            </ext:Panel>
       </Items>
    </ext:FitLayout>
    Last edited by geoffrey.mcgill; Jul 15, 2010 at 6:33 AM.
  8. #8
    I found the solution for the problem with the store.
    The store must be put into the page aspx-file.
    Thanks for your help.
    Klaus
  9. #9
    Now I have a lot of new problems:
    - If the store is outside of the usercontrol the selectbyvalue of the combo fires an javascript error the value and the selectedindex of the combo is ignored
    - If I use an inline store of the combobox inside the usercontrol and set the datasource in codebehind the value of the combobox is also ignored
    - Sinced I used render instead of updatecontent I can not find the usercontrol with FindControl
    :confused:

    EDIT: I made an example for the combobox problem

    How can I find a dynamicly added usercontrol in codebind or how can I get a reference to the usercontrol?
  10. #10
    Hi,

    The Render method must be called after all modifications but you call it before combo's store binding

    1. Move Render after DisplayCustomer calling
    Public Sub det_tobbtnsave_Click(ByVal sender As Object, ByVal e As Ext.Net.DirectEventArgs)
            Dim wucf1 As wuc_deteg001
    
            '---- load usercontrol
            Ext.Net.X.Call("destroyFromCache", def_pnlwuc01.ClientID)
            wucf1 = LoadControl("wuc_deteg001.ascx")
            wucf1.ID = "wuc_deteg001"
    
            def_pnlwuc01.ContentControls.Add(wucf1)
            Ext.Net.X.Call("putToCache", def_pnlwuc01.ClientID, wucf1.ControlsToDestroy)
    
    
    
            'some data for combo
            Dim Customers(1)() As String
            Customers(0) = New String() {"1", "Smith"}
            Customers(1) = New String() {"2", "Miller"}
    
            'combo in page
            det_Str_Customer.DataSource = Customers
            det_Str_Customer.DataBind()
            det_Cmb_CusId.Value = "1"
    
            'display data in usercontrol
            wucf1.Customers = Customers
            wucf1.DisplayCustomer()
    
            def_pnlwuc01.Render()
    
        End Sub
    2. Use the following DisplayCustomer (just use properties instead methods because control is dynamic)
    Public Sub DisplayCustomer()
    
            'text
            ucde01_Txt_CusId.Text = "1"
            ucde01_Txt_CusNo.Text = "No 1"
            ucde01_Txt_CadName1.Text = "Company 1"
    
            'combo with store
            ucde01_Customer.DataSource = Customers
            ucde01_Customer.DataBind()
            ucde01_Cmb_CusId.SelectedItem.Value = "1"
    
            'or
            'ucde01_Cmb_CusId.Value="1"
    
        End Sub
    Sinced I used render instead of updatecontent I can not find the usercontrol with FindControl
    I don't see in your sample where you call FindControl. I tried to find control after 'ContentControls.Add' and user control is found
    def_pnlwuc01.ContentControls.Add(wucf1)
    def_pnlwuc01.FindControl(wuc_deteg001) 'retrun result is not null
Page 1 of 2 12 LastLast

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