AutoLoadIFrame - load only when window shows

  1. #1

    AutoLoadIFrame - load only when window shows

    I have a window with ShowOnLoad = false and AutoLoadIFrame set. When the page loads, the iframe is also loaded. Is there a way to prevent that?
  2. #2

    RE: AutoLoadIFrame - load only when window shows

    Hi jchau,

    I did the same but setted also property Hidden="true" and it works well.

    Matteo
  3. #3

    RE: AutoLoadIFrame - load only when window shows

    Hi,

    You can just set url iframe after window showing (on client-side)

        <Click Handler="#{Window1}.show(); #{Window1}.loadIFrame('http://www.google.com/');" />

  4. #4

    RE: AutoLoadIFrame - load only when window shows

    You could also use an AjaxEvent when you want to show the window to set the AutoLoadIFrame:

    protected void Button1_Click(object sender, AjaxEventArgs e)
    {
        Window1.AutoLoadIFrame = "http://www.google.com";
        Window1.Show();
    }
    :)

    Cheers,
    Timothy
  5. #5

    RE: AutoLoadIFrame - load only when window shows

    I made a new DialogWindow class that inherits from Coolite.window. The new DialogWindow has the following functionalities:

    <ul>[*]IFrame loads when shown, not when rendered[*]Separation of url and querystring parameters[*]Ability to change query string parameters on client side[*]ReloadOnShow property to toggle whether IFrame will reload each time window is shown (this is used in conjunction with changing query string parameters on the fly)[/list]
  6. #6

    RE: AutoLoadIFrame - load only when window shows

    jchau,

    Very cool, any chance you can share that?


  7. #7

    RE: AutoLoadIFrame - load only when window shows

    I have to trim out alot of references/logic specific to our internal controls library so I hope this still compiles and works. The most important part is removing the listener for 'render' and adding a listener to 'show'.

    Javascrpt file
    Ext.ux.DialogWindow = Ext.extend(Ext.Window, {
        urlParams: {},
        reloadOnShow: true,
    
        initComponent: function() {
    
            Ext.ux.Dialogwindow.superclass.initComponent.call(this);
            if (this.autoLoadIFrame) {
                //remove listener that loads iframe on render
                this.un('render', this.doIFrameAutoLoad);
    
                //add listener to load iframe on show instead
                this.on('show', this.doIFrameAutoLoad, this);
            }
        },
    
        destroy: function() {
            Ext.ux.Dialogwindow.superclass.destroy.call(this);
        },
    
        doIFrameAutoLoad: function() {
            if ((this.reloadOnShow) || (Ext.isEmpty(this.iframe))) {
                this.loadIFrame(this.getFullIFrameURL());
            }
        },
    
        refreshIFrame: function() {
            if (!Ext.isEmpty(this.iframe)) {
                this.loadIFrame(this.getFullIFrameURL());
            }
        },
    
        getFullIFrameURL: function() {
            var url = this.autoLoadIFrame;
            var params = this.getURLParamsQueryString();
            if (params.length > 0) {
                url = url + '?' + params;
            }
            return url;
        },
    
        getURLParamsQueryString: function() {
            var sb = '';
            var isFirst = true;
    
            //make sure win id is part of params
            this.urlParams.winID = this.id;
    
            // loop through param to create param1=value1&amp;param2=value2...
            for (var param in this.urlParams) {
                var value = this.urlParams[param];
                if ((value) &amp;&amp; (value.length > 0)) {
                    if (isFirst) {
                        isFirst = false
                    }
                    else {
                        sb = sb + '&amp;';
                    }
                    sb = sb + param + '=' + this.urlParams[param];
                }
            }
    
            return sb;
        }
    
    });
    
    Ext.reg('dialog', Ext.ux.DialogWindow);
    Server file
    Imports Coolite.Ext.Web
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Web.UI
    
    <Assembly: WebResource("MyCoolite.Dialogwindow.js", "application/x-javascript")> 
    
    Namespace Controls
        <ClientScript(Type:=GetType(DialogWindow), WebResource:="MyCoolite.Dialogwindow.js")> _
        <ToolboxData("<{0}:DialogWindow runat=""server""></{0}:DialogWindow>")> _
        <Xtype("dialog")> _
        <InstanceOf(ClassName:="Ext.ux.DialogWindow")> _
        <ParseChildren(True)> _
        <PersistChildren(False)> _
        <System.ComponentModel.Designer(GetType(EmptyDesigner))> _
        Public Class DialogWindow
            Inherits Window
    
    
    #Region " Constructor "
            Public Sub New()
                MyBase.New()
    
                Me.ShowOnLoad = False
                Me.ShowIFrameMask = True
                Me.Modal = True
    
            End Sub
    #End Region
    
    #Region " Properties "
    
    #Region " Client Config "
            Private _ReloadOnShow As Boolean = True
            ''' <summary>
            ''' Toggle whether iframe will reload everytime window is shown
            ''' </summary>
            <ClientConfig("reloadOnShow")> _
            <DefaultValue(True)> _
            <Category("Config Options")> _
            Public Property ReloadOnShow() As Boolean
                Get
                    Return _ReloadOnShow
                End Get
                Set(ByVal value As Boolean)
                    _ReloadOnShow = value
                End Set
            End Property
    
            Private _URLParams As New Dictionary(Of String, String)
            ''' <summary>
            ''' Query string parameters to send to dialog
            ''' </summary>
            <ClientConfig("urlParams", GetType(JsonConverters.StringDictionaryJsonConverter))> _
            <DefaultValue(CType(Nothing, Object))> _
            <Category("Config Options")> _
            Public ReadOnly Property URLParams() As Dictionary(Of String, String)
                Get
                    If _URLParams Is Nothing Then _URLParams = New Dictionary(Of String, String)
                    Return _URLParams
                End Get
            End Property
    
    #End Region
    
    #End Region
    
    #Region " Life Cycle "
    
    
    #End Region
    
    #Region " Methods "
    
    #End Region
    
    
        End Class
    
    End Namespace
    JsonConverter
    Imports System
    Imports Coolite.Utilities
    Imports Newtonsoft.Json
    
    Namespace JsonConverters
    
        Public Class StringDictionaryJsonConverter
            Inherits JsonConverter
    
            Public Overloads Overrides Function CanConvert(ByVal valueType As Type) As Boolean
                Return GetType(Dictionary(Of String, String)).IsAssignableFrom(valueType)
            End Function
    
            Public Overloads Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal value As Object)
                Dim dictionary As Dictionary(Of String, String) = TryCast(value, Dictionary(Of String, String))
                If dictionary IsNot Nothing Then
                    Dim iterator As Dictionary(Of String, String).Enumerator = dictionary.GetEnumerator()
    
                    writer.WriteStartObject()
                    While iterator.MoveNext()
                        writer.WritePropertyName(iterator.Current.Key)
                        writer.WriteValue(iterator.Current.Value)
                    End While
                    writer.WriteEndObject()
    
                End If
            End Sub
    
            Public Overloads Overrides Function ReadJson(ByVal reader As Newtonsoft.Json.JsonReader, ByVal objectType As Type) As Object
                Throw New NotImplementedException()
            End Function
    
        End Class
    
    End Namespace
  8. #8

    RE: AutoLoadIFrame - load only when window shows

    Thanks for this!

    I'll give it a test.

Similar Threads

  1. Replies: 17
    Last Post: Dec 27, 2012, 5:56 AM
  2. [CLOSED] window AutoLoadIFrame property missing
    By digitek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 01, 2012, 12:05 PM
  3. [CLOSED] DateField calendar shows behind window
    By jchau in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 09, 2011, 5:37 PM
  4. Replies: 2
    Last Post: Oct 11, 2011, 1:15 PM
  5. Replies: 4
    Last Post: Oct 27, 2009, 6:15 AM

Posting Permissions