+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Control rendering *above* HTML tag despite position in content

Control rendering *above* HTML tag despite position in content

3 posts, 0 answered
  1. Nathan J Pledger
    Nathan J Pledger avatar
    27 posts
    Registered:
    21 Apr 2006
    12 Apr 2009
    Link to this post
    Hi,

    We're working on launching our new site in SiteFinity, and have hit another problem.

    I have the following UserControl code:

    1 using System; 
    2 using System.Collections; 
    3 using System.Configuration; 
    4 using System.Data; 
    5 using System.Linq; 
    6 using System.Web; 
    7 using System.Web.Security; 
    8 using System.Web.UI; 
    9 using System.Web.UI.HtmlControls; 
    10 using System.Web.UI.WebControls; 
    11 using System.Web.UI.WebControls.WebParts; 
    12 using System.Xml.Linq; 
    13 using System.Text; 
    14 using System.Xml; 
    15 using System.Xml.Xsl; 
    16 using System.Net; 
    17 using System.IO; 
    18  
    19 namespace ProgramX.ClearVision.ASPNET.WebApp.CVCmsResources.Panels 
    20
    21     public partial class RssExpander : System.Web.UI.UserControl 
    22     { 
    23         private string _sourceRssUrl; 
    24         private string _transformationXslt; 
    25     
    26
    27         #region ~ Properties ~ 
    28  
    29      
    30  
    31         public string SourceRssUrl 
    32         { 
    33             get { return _sourceRssUrl; } 
    34             set { _sourceRssUrl = value; } 
    35         } 
    36  
    37         public string TransformationXslt 
    38         { 
    39             get { return _transformationXslt; } 
    40             set { _transformationXslt = value; } 
    41         } 
    42
    43         #endregion 
    44  
    45         protected void Page_Load(object sender, EventArgs e) 
    46         { 
    47             XmlDocument xmlDocument; 
    48             XmlDocument xmlOutput; 
    49             XmlReader xmlReader; 
    50             XslTransform xslTransform; 
    51  
    52             xmlDocument = new XmlDocument(); 
    53             xmlOutput = new XmlDocument(); 
    54             xslTransform = new XslTransform(); 
    55  
    56             try 
    57             { 
    58                 string xml = GetWebRequest(_sourceRssUrl); 
    59                 xmlDocument.LoadXml(xml); 
    60                 xslTransform.Load(Server.MapPath(_transformationXslt)); 
    61  
    62                 xmlReader = xslTransform.Transform(xmlDocument, new XsltArgumentList()); 
    63                 xmlOutput.Load(xmlReader); 
    64  
    65                 Response.Write(xmlOutput.OuterXml); 
    66             } 
    67             catch (Exception ex) 
    68             { 
    69                 Response.Write("Cannot render: " + ex.Message); 
    70             } 
    71         } 
    72  
    73         private string GetWebRequest(string url) 
    74         { 
    75             // used to build entire input 
    76             StringBuilder sb = new StringBuilder(); 
    77  
    78             // used on each read operation 
    79             byte[] buf = new byte[8192]; 
    80  
    81             // prepare the web page we will be asking for 
    82             HttpWebRequest request = (HttpWebRequest) 
    83                 WebRequest.Create(url); 
    84  
    85             // execute the request 
    86             HttpWebResponse response = (HttpWebResponse) 
    87                 request.GetResponse(); 
    88  
    89             // we will read data via the response stream 
    90             Stream resStream = response.GetResponseStream(); 
    91  
    92             string tempString = null
    93             int count = 0; 
    94  
    95             do 
    96             { 
    97                 // fill the buffer with data 
    98                 count = resStream.Read(buf, 0, buf.Length); 
    99  
    100                 // make sure we read some data 
    101                 if (count != 0) 
    102                 { 
    103                     // translate from bytes to ASCII text 
    104                     tempString = Encoding.ASCII.GetString(buf, 0, count); 
    105  
    106                     // continue building the string 
    107                     sb.Append(tempString); 
    108                 } 
    109             } 
    110             while (count > 0); // any more data to read? 
    111  
    112             // print out page source 
    113             return sb.ToString(); 
    114         } 
    115     } 
    116
    117  
    118  

    So it's doing a WebRequest and spitting out some content through some XSLT. This works on my test harness (which I have had to create as SF ceased to compile its own code within a VS solution).

    Problem is, it renders content out fine, but renders ABOVE the HTML tag of the page. 

    We have placed the control (RssExpander) BELOW all content in the bottom-most contentPlaceholder.

    This is borne out by the following SQL:

    select ContaineriD,Ordinal,Type,IsAscx from sf_StagedCtrlLinks scl
    inner join sf_WebControlBase wcb ON wcb.ID=scl.ControliD
     where PageID='0207774C-6CF1-46C5-9854-7F8F9186F0EB'

    which returns:

    schoolsContent 0 ~/CVCmsResources/Silverlight/StudentsHome/StudentsHome.ascx 1
    schoolsContent 2 ~/CVCmsResources/Panels/RssExpander.ascx 1
    schoolsContent 1 Telerik.Cms.Engine.WebControls.GenericContent, Telerik.Cms.Engine, Version=3.6.1870.3, Culture=neutral, PublicKeyToken=dfeaee0e3978ac79 0

    If you want to see this in action, visit our test site at:

    http://clearvision.programx.co.uk/Schools/Students.aspx

    If it's unavailable, the original XHTML is:

    1 <div class="panel twoThirds"><h2>Student Blog</h2><div class="innerPanel"><ul class="panelBlog"><li><span class="articleTitle">Which boat should we blow up?</span><span class="articleHeader"><href="http://clearvision.programx.co.uk/Schools/Ask-a-Buddhist/Student-Blog/09-04-11/Which_boat_should_we_blow_up.aspx">Link</a> - Sat, 11 Apr 2009 17:32:08 GMT</span><span class="ArticleDescription">I dunno, but the orange is a fetching colour. 
    2 </span></li></ul></div></div> 
    3  
    4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    5  
    6 <html xmlns="http://www.w3.org/1999/xhtml"
    7 <head><link href="/css/screen.css" rel="stylesheet" type="text/css" media="screen" /> 
    8     <script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script> 
    9  
    10      
    11  
    12     <link href="/css/screen_school.css" rel="stylesheet" type="text/css" /> 
    13  
    14      
    15      
    16      
    17 <meta name="Generator" content="Sitefinity 3.6.1870.3" /><title
    18     Students 
    19 </title></head
    20 <body> 
    21     <form name="aspnetForm" method="post" action="Students.aspx" id="aspnetForm"
    22 <div> 
    23 <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> 
    24 <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> 
    25 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUENTM4MQ9kFgJmD2QWAmYPZBYCAgMQZGQWAgIHD2QWAgIBDxYCHgRocmVmBSAvSG9tZS9Pbi1saW5lLVNob3AvQ2hlY2tvdXQuYXNweGQYAQU6Y3RsMDAkY3RsMDAkdG9wTGV2ZWxDb250ZW50JHNjaG9vbHNDb250ZW50JEdlbmVyaWNDb250ZW50MQ8UKwABZGSTt+xcScGQSRPUIrr3Zrc7sus0+Q==" /> 
    26 </div> 
    27  
    28 <script type="text/javascript"
    29 //<![CDATA[
    30 var theForm = document.forms['aspnetForm'];
    31 if (!theForm) {
    32     theForm = document.aspnetForm;
    33 }
    34 function __doPostBack(eventTarget, eventArgument) {
    35     if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
    36         theForm.__EVENTTARGET.value = eventTarget;
    37         theForm.__EVENTARGUMENT.value = eventArgument;
    38         theForm.submit();
    39     }
    40 }
    41 //]]> 
    42 </script> 
    43  
    44  
    45 <script src="/WebResource.axd?d=icLt6HQKhjC1T1aCljjdbg2&amp;t=633667457940987677" type="text/javascript"></script> 
    46  
    47  
    48 <script src="/ScriptResource.axd?d=Bj7r0p5eYPBj85REve9XqQ-BoDGYVsKgyyJpjxvgrE9NpTvRQmNXsZqygdX35xuKnCZ_IvPXdTrifEMYfe1mYhS2vbqhUfPTY_wmNjNNh8U1&amp;t=633667466247600101" type="text/javascript"></script> 
    49 <script type="text/javascript"
    50 //<![CDATA[
    51 if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
    52 //]]> 
    53 </script> 
    54  
    55 <script src="/ScriptResource.axd?d=Bj7r0p5eYPBj85REve9XqQ-BoDGYVsKgyyJpjxvgrE9NpTvRQmNXsZqygdX35xuKU0OuQcRZg6uHLLRsmT4HLCr1SkQbmh4rY-_RCm1VzTX1CG-5JF6HAwPbeQlSKJ7B0&amp;t=633667466247600101" type="text/javascript"></script> 
    56         <script type="text/javascript"
    57 //<![CDATA[
    58 Sys.WebForms.PageRequestManager._initialize('ctl00$ctl00$ScriptManager1', document.getElementById('aspnetForm'));
    59 Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);
    60 //]]> 
    61 </script> 
    62  
    63         <div id="headerWrapper" class="sectionHeader"
    64              
    65             <div id="headerInner"
    66                 <h1 id="logoPharc">Clear Vision Trust</h1> 
    67                 <h2 class="hide">Audio-visual resources exploring Buddhism</h2> 
    68                 <div id="topNav"
    69                     <ul> 
    70                         <li><a href="/" title="Home page" accesskey="0">Home</a></li>                    
    71                         <li><a href="#" title="About us" accesskey="a">About us</a></li>                     
    72                         <li><a href="#" title="Search" accesskey="f">Search</a></li>                     
    73                         <li><a href="#" title="Donate" accesskey="d">Donate</a></li>                     
    74                     </ul> 
    75                 </div> 
    76                  
    77                 <div id="channelNav"
    78                     <ul> 
    79                         <li id="channelNavSchools"
    80                             <href="/Schools.aspx" title="Schools" accesskey="s">Schools</a> 
    81                             <ul> 
    82                                 <li><a href="#" title="Students">Students</a></li
    83                                 <li><a href="#" title="Ask a Buddhist">Ask a Buddhist!</a></li
    84                                 <li><a href="#" title="Teachers">Teachers</a></li
    85                                 <li><a href="#" title="Images">Images</a></li
    86                             </ul> 
    87                         </li> 
    88                         <li id="channelNavHomeUse"
    89                             <href="/Home-Use.aspx" title="Home use" accesskey="h">Home use</a> 
    90                             <ul> 
    91                                 <li><a href="#" title="FWBO Photos"><acronym title="First Western Buddhist Order">FWBO</acronym> Photos</a></li
    92                                 <li><a href="#" title="FWBO Video"><acronym title="First Western Buddhist Order">FWBO</acronym> Video</a></li
    93                                 <li><a href="#" title="Ask a Buddhist">Ask a Buddhist!</a></li
    94                                 <li><a href="#" title="Young Buddhist">Young people</a></li
    95                             </ul> 
    96                         </li> 
    97                     </ul> 
    98                 </div> 
    99                  
    100                 <div id="tabWrapper"
    101                     <ul class="tabs"><li class="tabCornerTL tabSelected"><href="/Schools/Students.aspx" title="Students" class="tabCornerTR">Students</a></li><li class="tabCornerTL"><href="/Schools/Ask-a-Buddhist.aspx" title="Ask a Buddhist" class="tabCornerTR">Ask a Buddhist</a></li><li class="tabCornerTL"><href="/Schools/Teachers.aspx" title="Teachers" class="tabCornerTR">Teachers</a></li><li class="tabCornerTL"><href="/Schools/Images.aspx" title="Images" class="tabCornerTR">Images</a></li></ul> 
    102                     <ul class="tabSubNav"><li><a href="/Schools/Students/Ages-4-7.aspx" title="Ages 4-7">Ages 4-7</a></li><li><a href="/Schools/Students/Ages-8-11.aspx" title="Ages 8-11">Ages 8-11</a></li><li><a href="/Schools/Students/Ages-12-14.aspx" title="Ages 12-14">Ages 12-14</a></li><li><a href="/Schools/Students/Ages-15-16.aspx" title="Ages 15-16">Ages 15-16</a></li><li><a href="/Schools/Students/Ages-17-18.aspx" title="Ages 17-18">Ages 17-18</a></li></ul> 
    103                      
    104                              
    105 <div id="basketTab"
    106     <p><strong>Basket:</strong> 
    107         <href="/Home/On-line-Shop/Checkout.aspx" id="ctl00_ctl00_basketTab_aBasketLink" accesskey="9" tabindex="9" title="Basket">No Items</a> 
    108     </p> 
    109 </div>                           
    110                              
    111  
    112                          
    113                          
    114                          
    115                          
    116                      
    117  
    118                 </div> 
    119                  
    120                  
    121                  
    122                  
    123                  
    124             </div> 
    125              
    126         </div> 
    127         <div id="contentWrapper"
    128          
    129          
    130          
    131              
    132  
    133     <div id="schoolsContent"
    134                      
    135          
    136          
    137          
    138  
    139 <script type="text/javascript" src="/js/Silverlight.js"></script> 
    140 <script type="text/javascript" src="/js/InstallCreateSilverlight.js"></script> 
    141 <script type="text/javascript" src="/CVCmsResources/Silverlight/StudentsHome/Page.xaml.js"></script> 
    142  
    143 <style type="text/css"
    144     #silverlightControlHost { 
    145         height: 245px; 
    146         width: 900px; 
    147     } 
    148     #errorLocation { 
    149         font-size: small; 
    150         color: Gray; 
    151     } 
    152 </style> 
    153  
    154 <script type="text/javascript"
    155     function createSilverlight() 
    156     { 
    157         var scene = new BarScroller.Page(); 
    158         Silverlight.createObjectEx({ 
    159             source: "/CVCmsResources/Silverlight/StudentsHome/Page.xaml", 
    160             parentElement: document.getElementById("silverlightControlHost"), 
    161             id: "SilverlightControl", 
    162             properties: { 
    163                 width: "100%", 
    164                 height: "100%", 
    165                 version: "1.0" 
    166             }, 
    167             events: { 
    168                 onLoad: Silverlight.createDelegate(scene, scene.handleLoad), 
    169                 onError: function(sender, args) { 
    170                     var errorDiv = document.getElementById("errorLocation"); 
    171                     if (errorDiv != null) { 
    172                         var errorText = args.errorType + "- " + args.errorMessage; 
    173                                  
    174                         if (args.ErrorType == "ParserError") { 
    175                             errorText += "<br>File: " + args.xamlFile; 
    176                             errorText += ", line " + args.lineNumber; 
    177                             errorText += " character " + args.charPosition; 
    178                         } 
    179                         else if (args.ErrorType == "RuntimeError") { 
    180                             errorText += "<br>line " + args.lineNumber; 
    181                             errorText += " character " +  args.charPosition; 
    182                         } 
    183                         errorDiv.innerHTML = errorText
    184                     }    
    185                 } 
    186             } 
    187         }); 
    188     } 
    189  
    190     if (!window.Silverlight) { 
    191         $('#silverlightFailover').css('display','block'); 
    192         $('#silverlightControlHost').css('display','none'); 
    193         alert('no silverlight'); 
    194     } 
    195  
    196     if (!window.Silverlight)  
    197         Silverlight = {}; 
    198  
    199     Silverlight.createDelegate = function(instance, method) { 
    200         return function() { 
    201             return method.apply(instance, arguments); 
    202         } 
    203     } 
    204      
    205      
    206                  
    207          
    208 </script> 
    209  
    210 <style type="text/css"
    211     div#silverlightFailover { display: none; } 
    212     div#silverlightFailover ul { margin: 0px; padding: 0px; list-style-type: none; } 
    213     div#silverlightFailover ul li { margin: 0px; padding: 0px; float: left; } 
    214     div#silverlightFailover ul li a { } 
    215     div#silverlightFailover ul li a img { border: none; } 
    216     div#silverlightFailover p#getSilverlight { margin-top: -50px; float: right; padding: 10px;} 
    217     div#silverlightFailover p#getSilverlight a { } 
    218     div#silverlightFailover p#getSilverlight a img { border: none; } 
    219      
    220 </style> 
    221  
    222 <div id="silverlightFailover"
    223     <ul> 
    224         <li><a href="Ages-4-7.aspx" title="Ages 4-7"><img src="/CVCmsResources/Silverlight/StudentsHome/images/Failover_01.jpg" width="177" height="244" alt="Ages 4-7"></a></li
    225         <li><a href="Ages-8-11.aspx" title="Ages 8-11"><img src="/CVCmsResources/Silverlight/StudentsHome/images/Failover_02.jpg" width="177" height="244" alt="Ages 8-11"></a></li
    226         <li><a href="Ages-12-14.aspx" title="Ages 12-14"><img src="/CVCmsResources/Silverlight/StudentsHome/images/Failover_03.jpg" width="177" height="244" alt="Ages 12-14"></a></li
    227         <li><a href="Ages-15-16.aspx" title="Ages 15-16"><img src="/CVCmsResources/Silverlight/StudentsHome/images/Failover_04.jpg" width="177" height="244" alt="Ages 15-16"></a></li
    228         <li><a href="Ages-17-18.aspx" title="Ages 17-18"><img src="/CVCmsResources/Silverlight/StudentsHome/images/Failover_05.jpg" width="177" height="244" alt="Ages 17-18"></a></li
    229     </ul> 
    230     <id="getSilverlight"
    231         <href="#" title=""><img src="/images/GetSilverlight.jpg" alt="" /></a
    232     </p> 
    233 </div> 
    234 <div id="silverlightControlHost"
    235     <script type="text/javascript"
    236         if (window.Silverlight) { 
    237             createSilverlight();} 
    238     </script> 
    239 </div> 
    240      
    241 <div id='errorLocation'></div> 
    242     <h1>Students</h1> <div style="height: 500px;"<div class="twoThirds"<div class="panel"<h2>Student Blog</h2> <div class="innerPanel"<p>Post 1</p> </div> <div class="innerPanel"<p>Post 2</p> </div> </div> <div class="panel"<h2>Images</h2> <div class="innerPanel"<p>Images (free)</p> </div> </div> </div> <div class="panel third"<h2>Ask a Buddhist</h2> <div class="innerPanel"<p>Why does the Buddha have big ears?</p> </div> <div class="innerPanel"<p>Didn't you know?</p> </div> </div> </div> 
    243  
    244      
    245     </div> 
    246  
    247  
    248              
    249             <div id="footer"
    250                 <ul> 
    251                     <li><a href="#" title="Home">Home</a> 
    252                         <ul> 
    253                             <li><a href="#" title="The Trust">The Trust</a></li
    254                             <li><a href="#" title="Visit us">Visit us</a></li
    255                             <li><a href="#" title="Blog">Blog</a></li
    256                             <li><a href="#" title="Forum">Forum</a></li
    257                             <li><a href="#" title="On-line shop">On-line shop</a></li
    258                         </ul> 
    259                     </li> 
    260                     <li><a href="#" title="Home">Schools</a> 
    261                         <ul> 
    262                             <li><a href="#" title="Students">Students</a></li
    263                             <li><a href="#" title="Ask a Buddhist">Ask a Buddhist!</a></li
    264                             <li><a href="#" title="Teachers">Teachers</a></li
    265                             <li><a href="#" title="Images">Images</a></li
    266                         </ul> 
    267                     </li> 
    268                     <li><a href="#" title="Home">Home Use</a> 
    269                         <ul> 
    270                             <li><a href="#" title="FWBO Images"><acronym title="First Western Buddhist Order">FWBO</acronym> Images</a></li
    271                             <li><a href="#" title="FWBO Video"><acronym title="First Western Buddhist Order">FWBO</acronym> Video</a></li
    272                             <li><a href="#" title="Ask a Buddhist">Ask a Buddhist!</a></li
    273                             <li><a href="#" title="Young people">Young people</a></li
    274                         </ul> 
    275                     </li> 
    276                     <li><a href="#" title="Home">On-line Shop</a> 
    277                         <ul> 
    278                             <li><a href="#" title="Your Basket">Your Basket</a></li
    279                             <li><a href="#" title="Our Customer Policy">Our Customer Policy</a></li
    280                             <li><a href="#" title="Secure Payment">Secure Payment</a></li
    281                             <li><a href="#" title="Shipping">Shipping</a></li
    282                             <li><a href="#" title="PayPal">PayPal</a></li
    283                         </ul> 
    284                     </li> 
    285                     <li><a href="#" title="Home">&copy; The Clear Vision Trust</a> 
    286                         <ul> 
    287                             <li><address>16-20 Turner Street<br /> 
    288                                 Manchester, M4 1DZ</address>                                 
    289                             </li> 
    290                             <li><br /><abbr title="Telephone Number">t:</abbr> 0161 839 9579</li> 
    291                             <li><br /><abbr title="Fax Number">f:</abbr> 0870 134 7354</li> 
    292                             <li><br /><a href="#" title="Terms of Use">Terms of Use</a></li
    293                         </ul> 
    294                     </li> 
    295                     <li class="siteFinityLogo"><href="http://www.sitefinity.com" title="SiteFinity site (external link)">powered by SiteFinity</a></li>                    
    296                 </ul>            
    297             </div> 
    298         </div> 
    299  
    300     <id="ctl00_ctl00_sitefinityLogo" style="overflow: visible ! important; text-align: center ! important; display: block ! important; visibility: visible ! important; position: static ! important;" class="poweredBySitefinityLogo"><href="http://www.sitefinity.com" rel="external" style="display: block ! important; visibility: visible ! important; position: static ! important; border: 0 !important;width: 139px ! important; height: 51px ! important; background: transparent url(/WebResource.axd?d=90VQuHO9EV_GCDLYPWSMVKLu2nPJbzm8Ea6EWJV9MdIMdPcvpkwbJ5dXCJOnpPRX1Bkovq83mVVYr_6QedO67g2&amp;t=633746351428378109) no-repeat 0 0 ! important; text-indent: -9999px ! important; margin: 0 auto !important; padding: 0 !important; outline: 0 !important; " title="Sitefinity ASP.NET CMS">Sitefinity ASP.NET CMS</a></p
    301  
    302 <script type="text/javascript"
    303 //<![CDATA[
    304 Sys.Application.initialize();
    305 //]]> 
    306 </script> 
    307 </form> 
    308 </body> 
    309 </html> 
    310  
    311  

    Thanks

  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    14 Apr 2009
    Link to this post
    Hi Nathan,

    Seems the problem is in the user control, because on Page_Load it calls Response.Write to output the data directly into the current Response, despite the control position. At this stage the Response output is empty, so it writes the string on the top.
    To fix the problem you should write the data in a control which is placed in the user control.
    However, a better approach would be to implement the logic in Render method of the user control:

        protected override void Render(HtmlTextWriter writer) 
        { 
            XmlDocument xmlDocument;  
            XmlDocument xmlOutput;  
            XmlReader xmlReader;  
            XslTransform xslTransform;  
     
            xmlDocument = new XmlDocument();  
            xmlOutput = new XmlDocument();  
            xslTransform = new XslTransform();  
     
            try  
            {  
                string xml = GetWebRequest(_sourceRssUrl);  
                xmlDocument.LoadXml(xml);  
                xslTransform.Load(Server.MapPath(_transformationXslt));  
     
                xmlReader = xslTransform.Transform(xmlDocument, new XsltArgumentList());  
                xmlOutput.Load(xmlReader); 
     
                writer.Write(xmlOutput.OuterXml);  
            }  
            catch (Exception ex)  
            {  
                Response.Write("Cannot render: " + ex.Message);  
            }  
            base.Render(writer); 
        } 

    I hope this is helpful.

    Kind regards,
    Vlad
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Nathan J Pledger
    Nathan J Pledger avatar
    27 posts
    Registered:
    21 Apr 2006
    14 Apr 2009
    Link to this post
    Hi Vlad,

    That's got it.

    Thanks a lot.
Register for webinar
3 posts, 0 answered