Dynamic server side include containing a control

L

Larry

Hi,

I need a method to dynamically include a server side include in my
asp.net page. The problem is, the include file contains asp.net
controls, and I can't find a way to get the controls to render.

HISTORY

I have an active website. I have about 100 include files that are just
html text. In .aspx page, I have the following:

<% response.writefile(fcnGetInclude()) %>

Where fcnGetInclude is a function that tests the current querystring
and dynamically selects an inlcude file to write from.

Works great.

CURRENT SITUATION

Now, each of those 100 include files has an asp.net control in it.
Under the above scenario the control doesn't render because it's being
written to the page too late.

I need a way to dynamically select and include a server side include
file before the page renders on the server.

I'm open to using a database read instead of the include files, but I
believe I'll run into the same issue. The database read needs to be
done before the page is rendered on the server, so I think page_load
and page_init are too late.

Can anyone help me out?
 
G

Guest

If you need to dyanmically render sets of functionality, you need a container
(Panel, for example) on the page. You then attach controls to the container's
panel colllection. You cannot use a "server side include" from the
traditional HTML venue (probably a way, but since you can solve this by
placing controls on the page, why spend the time?).

Here is a poor man's control loader (ascx) for numbered controls:

private void LoadControl(int controlID)
{
StringBuilder builder = new StringBuilder();
builder.Append("controls\\ctl");
builder.Append(reportDefinitionID.ToString());
builder.Append(".ascx");

//for #1 builder.ToString = "controls\ctl1.ascx"

Control userControl = LoadControl(builder.ToString());
ReportControlPanel.Controls.Add(userControl);
}

This should give you some ideas.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
L

Larry

Gregory,

I wanted to followup and say thanks for this code. Taught me a good
lesson, and it's just what I needed.

Why did you feel it necessary to overload LoadControl instead giving
your subroutine it's own name? Is there something about conventions or
best practices involved?

Larry
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top