Dynamic server side include containing a control

Discussion in 'ASP .Net' started by Larry, Feb 14, 2006.

  1. Larry

    Larry Guest

    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?
     
    Larry, Feb 14, 2006
    #1
    1. Advertising

  2. 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?
    >
    >
     
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Feb 14, 2006
    #2
    1. Advertising

  3. Larry

    Larry Guest

    Ok, I think I get the idea. I'll try it out.

    Thanks.
     
    Larry, Feb 14, 2006
    #3
  4. Larry

    Larry Guest

    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
     
    Larry, Feb 20, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mythran
    Replies:
    2
    Views:
    534
    Mythran
    Jan 22, 2005
  2. Mark
    Replies:
    4
    Views:
    648
    Steve C. Orr [MVP, MCSD]
    May 11, 2005
  3. Replies:
    2
    Views:
    376
  4. Andreas Bogenberger
    Replies:
    3
    Views:
    973
    Andreas Bogenberger
    Feb 22, 2008
  5. Replies:
    3
    Views:
    156
    William James
    Jul 25, 2006
Loading...

Share This Page