Is it possible to have a method that return a string with ASP.NET code get called in an aspx file and have that code run before the page is reloaded?
So pretty much have something like the following:
<asp:DataList //blahblah>
<ItemTemplate>
<%= GenerateTable() %>
</ItemTemplate>
</asp:DataList>
GenerateTable() creates a table with asp:Label objects in them whose values are determined by the DataSource of the asp:DataList.
Right now, I have the ASP.NET code generating properly. The problem is that it's not translated into HTML before the page loads so you can't see it.
Update: The reason why I want a separate method for generating the ASP.NET code is because I want to make the columns displayed configurable, so the same columns are not always displayed by the website.
Update for Solution Attempt: I tried creating the following User Control to insert my ASP.NET code, but it's still running into the same problem. Am I doing this wrong?
User Control:
<%@ Control Language="C#" CodeBehind="TableGenerator.ascx.cs" Inherits="DagReport_WebRole.DynamicData.FieldTemplates.TableGenerator" %>
<div class="tableRow">
<%= this.GetASPCode() %>
</div>
User Control C#: using System.Web.UI;
namespace DagReport_WebRole.DynamicData.FieldTemplates
{
public partial class TableGenerator : System.Web.DynamicData.FieldTemplateUserControl
{
public string Code { get; set; }
public string GetASPCode()
{
return Code;
}
}
}
In My ASPX File:
<ItemTemplate>
<div class="dagRow"></div>
<userControl:TableGenerator
Code="<%=GetRowASPCode()%>"></userControl:TableGenerator>
</ItemTemplate>
