i’m seeing a really strange issue with asp.net rendering. i have EXACTLY this in the relevant part of the .aspx (just replaced names of paths and controls):
<div id="header">
<% if (SiteSettings.SiteName.Equals("sx") || SiteSettings.SiteName.Equals("sw"))
{ %>
<sc:sublayout runat="server" renderingid="{B04CFA1A-6B5B-49D3-8000-339DBE9899C1}"
path="/layouts/AX/HeaderSublayout.ascx" id="AXHeader" placeholder="content"></sc:sublayout>
<% }
else
{ %><!-- bla1 --><ax:strangeBehavingControl id="HeaderInclude" runat="server" IncludeType="Header" /><!-- bla2 -->
<% } %>
</div>
the rendered html looks like:
<!-- bla1 -->
""
expected content from strangeBehavingControl
<!-- bla2 -->
the .ascx for strangeBehavingControl is really simple:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="strangeBehavingControl.ascx.cs" Inherits="layouts.strangeBehavingControl" %>
no extra spaces anywhere, checked already many times. the code behind is also really simple:
public partial class strangeBehavingControl: System.Web.UI.UserControl
{
protected override void Render(HtmlTextWriter writer)
{
var filePath = GetFilePath();
if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(Server.MapPath(filePath)))
Response.WriteFile(filePath);
}
}
so i was thinking that the strange “” where inside the rendered included files, but i checked them manually and they start with the expected characters. any idea how can those characters being inserted there?
You are generating markup for your control incorrectly. Your render method should be using the
HtmlTextWriterinstance given to it, and not using any direct output writing method onResponse.It also looks like a rather strange setup, as you are writing out the contents as a
UserControl, meaning it will be rendered within a page. Is it correct to assume you are always outputting either valid HTML or plain text?I would suggest you change your
Rendermethod as follows: