More in this section

Forums / Developing with Sitefinity / User Control only renders after a page refresh

User Control only renders after a page refresh

2 posts, 0 answered
  1. Trever Archibald
    Trever Archibald avatar
    2 posts
    Registered:
    01 Dec 2009
    22 Dec 2009
    Link to this post

    Hello, we have a video player user-control that appears fine on most pages. In most cases the page loads and displays the control just fine. On some occasions the page requires a refresh in order for the control to render. We're passing parameters to the control via viewstate like this:

      /// <summary> 
        /// Auto Play video when loaded  
        /// </summary> 
        [Description("Specify whether the video should start automatically when loaded.")]  
        public bool AutoStart  
        {  
            get  
            {  
                if (ViewState["AutoStart"] == null)  
                    return DefaultAutoStart;  
                else  
                    return (bool)ViewState["AutoStart"];  
            }  
            set  
            {  
                if (value != DefaultAutoStart)  
                    ViewState["AutoStart"] = value;  
                else  
                    ViewState["AutoStart"] = null;  
            }  
        }  
     
        /// <summary> 
        /// URI to Video File to Play  
        /// </summary> 
        [Description("Select a video to be displayer in the player.  [Library] filename (type)")]  
        [WebEditor("VideoLibraryFileSelector, App_Code")]  
        public string Video  
        {  
            get  
            {  
                if (ViewState["VideoFile"] == null)  
                {  
                    return selectedVideo;  
                }  
                else  
                {  
                    return (string)ViewState["VideoFile"];  
                }  
            }  
            set  
            {  
                if (value != selectedVideo)  
                {  
                    selectedVideo = value;  
                    ViewState["VideoFile"] = value;  
                }  
                else  
                {  
                    ViewState["VideoFile"] = null;  
                }  
            }  
        }  
     
        [Category("Video Sizing")]  
        [Description("This will be the actual height of the player")]  
        public string Height { get; set; }  
     
        [Category("Video Sizing")]  
        [Description("This will be the actual width of the player")]  
        public string Width { get; set; } 


    Then we render the control via the object tag:

     public void RenderSilverlightPlayer()  
        {  
            if (!string.IsNullOrEmpty(Video) && Video.Split('|').Length > 1)  
            {  
                StringBuilder content = new StringBuilder();  
                content.AppendLine(@"<div id='silverlightControlHost'>");  
     
                if (string.IsNullOrEmpty(Width))  
                {  
                    Width = "535";  
                }  
     
                if (string.IsNullOrEmpty(Height))  
                {  
                    Height = "301";  
                }  
     
                content.AppendFormat(@"<object data='data:application/x-silverlight,'type='application/x-silverlight' width='{0}' height='{1}'>", Width, Height);  
                content.AppendLine("");  
                content.AppendLine(@"<param name='source' value='" + ClientBinPath + "'/>");  
                content.AppendLine(@"<param name='onError' value='onSilverlightError'/>");  
                content.AppendLine(@"<param name='background' value='transparent'/>");  
                content.AppendLine(@"<param name='minRuntimeVersion' value='3.0.40624.0'/>");  
                content.AppendLine(@"<param name='EnableGPUAcceleration' value='true'/>");  
                content.AppendLine(@"<param name='autoUpgrade' value='true'/>");  
                content.AppendFormat(@"<param name='InitParams' value='m={0}'/>", _initParams);  
                content.AppendLine("");  
                content.AppendLine(@"<href='http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0' style='text-decoration: none'>");  
                content.AppendLine(@"<img src='http://go.microsoft.com/fwlink/?LinkId=108181' alt='Get Microsoft Silverlight' style='border-style: none'/>");  
                content.AppendLine(@"</a>");  
                content.AppendLine(@"</object>");  
                content.AppendLine(@"<iframe id='_sl_historyFrame' style='visibility: hidden; height: 0px; width: 0px; border: 0px'></iframe>");  
                content.AppendLine(@"</div>");  
                litFlashUC.Text = content.ToString();  
            }  
        } 
     When viewing page source the object tag looks correct even in instances where the control does not render properly. In the cases it does not render properly a page refresh usually does the trick. Is there anything we can do to handle this behavior?

    Thanks
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    28 Dec 2009
    Link to this post
    Hello Trever Archibald,

    Can you please try the same control on a regular aspx page? 

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered