Dynamically loaded aspx content not shoing up in DNN Module

237 views Asked by At

I have a DNN module that needs to load some different content based on the log-in roles that can be easily changed without recompiling the module. I am attempting to load an aspx file to a literal object.

StringBuilder SB = new StringBuilder();
using (StreamReader SR = new StreamReader("test.aspx"))
{
     while(!SR.EndOfStream){
         string line = SR.ReadLine();
         SB.Append(line);
     }
     SR.Close();
}

//ltl1 is <asp:Literal runat="server" ID="ltl1" >
ltl1.Text = SB.ToString();

object test1 = ltl1.FindControl("txtTextBox1");
object test2 = ltl1.FindControl("txtTextBox2");
lblInformation.Text = "Loaded:"
lblInformation.Text += (test1 == null ? " NULL1" : test1.ToString()) 
lblInformation.Text += (test2 == null ? " NULL2" : test2.ToString());

Loading this file:

<div runat="server" ID="divMain">
    <b>TEST FILE</b>
    <br />
    <input runat="server" ID="txtTestBox1" />
    <asp:TextBox runat="server" ID="txtTestBox2" />
</div>

If I inspect the source code it looks like this:

 <div runat="server" id="divMain">  
     <b>TEST FILE</b>   
     <br>   
     <input runat="server" id="txtTestBox1">    </input>
     <asp:textbox runat="server" id="txtTestBox2"></asp:textbox>
 </div>

However there is only the <input> textbox, the <asp:TextBox> isn't visible in the browser. In addition, neither of them are visible from the C# code behind as

lblInformation.Text = Loaded: NULL1 NULL2

What I need is either access to the <input> textbox or for the <asp:textbox> to show up. Or a completely different way that works.

1

There are 1 answers

0
Chris Hammond On BEST ANSWER

You would use an ASCX file into a DNN module, not an ASPX file. There are some examples of how to load ASCX files into other ASCX files in DNN in my DNN Simple Article module (https://dnnsimplearticle.codeplex.com/SourceControl/latest#cs/View.ascx.cs)