Include file with System.Reflection

P

porter

I am very new to C#. I have a block of code (a web control) that I
want to include a file. In my mind, I want to include it in-line,
like php would include a file -- execute any code and then render
html.

But, i've been reading and it sounds like thats not the case with C#.
Im not opposed to learning a new method, im just lost trying to find
the right way to phrase my questions to google or groups tutorials.

Here is my code

Control loadThis ;

switch (url) {
case "news":
loadThis = LoadControl(page + "news.ascx");
break;

case "othercase":
loadThis = LoadControl(page + "othercase.ascx");
break;
}

I want the page news.ascx (which is just some code to parse a multi-
dimensional array) to actually execute code and not just display the
code as if it was one big string...which it does currently. If there
is a simple "execute" or something of the sort, I would prefer that
because this project is relatively small scale...

I did read that using System.Reflection is the best method to
dynamically include a file but...there was no example and so I dont
know how? Microsoft's documentation was more than a little
confusing. If there is a simple explanation of how to use this class,
could someone please explain or if not, could you point me in the
right direction, maybe give me some keywords to search google (I dont
even know the name of the method im looking for haha)

thanks in advance
 
G

Guest

hi plz try this one
protected void Page_Load(object sender, EventArgs e)
{
Control c=(news)LoadControl("news.ascx");
c.ID = "control1";
form1.Controls.Add(c);

}

u need to cost ur control then addit to form control collection .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top