473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dynamic server side include containing a control

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?

Feb 14 '06 #1
3 1583
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!
***************************
"Larry" wrote:
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?

Feb 14 '06 #2
Ok, I think I get the idea. I'll try it out.

Thanks.

Feb 14 '06 #3
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

Feb 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
2
by: Alan Searle | last post by:
I find that I can display structured data very nicely using XML with an XSL template. As an extra 'goodie', I would like to give users the ability to sort that data (for example with a button...
3
by: IRAS Blues | last post by:
Hi all, I've got a form that consists of a bunch of textboxes and also file upload inputs. For both sets of fields, I need to be able to add in additional elements on the fly. This is done by an...
5
by: RA | last post by:
I have created a button dynamically; which has been added to a TableCell of a TableRow of a Table control. Is there a way to add onclick event which calls a procedure on the Server-side itself....
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
7
by: Abraham Luna | last post by:
how do i stop the dynamic validators from breaking explorer if i use a dynamic validator and move to a different control it breaks explorer and i can type in the page when i'm not supposed to....
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
1
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.