Adding controls to Page.Controls collection

Discussion in 'ASP .Net' started by Jeremy Ames, Mar 4, 2004.

  1. Jeremy Ames

    Jeremy Ames Guest

    I have run into a major road block with my page development projects. I am
    trying to add a literal control to my asp.net page and I got an error
    stating that the control could not be added because of code blocks (<% %>)
    on the page. Most of these blocks can be handled by adding a label control
    to the form so it is not that big of deal, but one of the things being
    posted is the page title. I am not sure how I can access that from the code
    behind page. I also call a function that creates a css style sheet as well
    as a function that creates my navigation bar for the web site. Is there a
    way for me to get around the error without moving the code blocks? If not,
    how can I implement the changes for the three problem areas?
     
    Jeremy Ames, Mar 4, 2004
    #1
    1. Advertising

  2. Try adding a panel and then adding the control to the panel. As I have not
    worked with <% %> blocks, this is just a guess, but the panel makes a better
    container for controls than Page, IMO.

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

    **********************************************************************
    Think Outside the Box!
    **********************************************************************
    "Jeremy Ames" <> wrote in message
    news:%...
    > I have run into a major road block with my page development projects. I am
    > trying to add a literal control to my asp.net page and I got an error
    > stating that the control could not be added because of code blocks (<% %>)
    > on the page. Most of these blocks can be handled by adding a label control
    > to the form so it is not that big of deal, but one of the things being
    > posted is the page title. I am not sure how I can access that from the

    code
    > behind page. I also call a function that creates a css style sheet as well
    > as a function that creates my navigation bar for the web site. Is there a
    > way for me to get around the error without moving the code blocks? If not,
    > how can I implement the changes for the three problem areas?
    >
    >
     
    Cowboy \(Gregory A. Beamer\), Mar 4, 2004
    #2
    1. Advertising

  3. Jeremy Ames

    bruce barker Guest

    if you are framework 1.1,

    <title id=title runat=server>

    will showup on the codebehind as a generic html control, which you can set
    attributes or innerhtml.

    -- bruce (sqlwork.com)



    "Jeremy Ames" <> wrote in message
    news:#...
    > I have run into a major road block with my page development projects. I am
    > trying to add a literal control to my asp.net page and I got an error
    > stating that the control could not be added because of code blocks (<% %>)
    > on the page. Most of these blocks can be handled by adding a label control
    > to the form so it is not that big of deal, but one of the things being
    > posted is the page title. I am not sure how I can access that from the

    code
    > behind page. I also call a function that creates a css style sheet as well
    > as a function that creates my navigation bar for the web site. Is there a
    > way for me to get around the error without moving the code blocks? If not,
    > how can I implement the changes for the three problem areas?
    >
    >
     
    bruce barker, Mar 4, 2004
    #3
  4. Jeremy Ames

    Jeremy Ames Guest

    The literal that I am loading is Javascript. Will that work in a panel?

    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:...
    Try adding a panel and then adding the control to the panel. As I have not
    worked with <% %> blocks, this is just a guess, but the panel makes a better
    container for controls than Page, IMO.

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

    **********************************************************************
    Think Outside the Box!
    **********************************************************************
    "Jeremy Ames" <> wrote in message
    news:%...
    > I have run into a major road block with my page development projects. I am
    > trying to add a literal control to my asp.net page and I got an error
    > stating that the control could not be added because of code blocks (<% %>)
    > on the page. Most of these blocks can be handled by adding a label control
    > to the form so it is not that big of deal, but one of the things being
    > posted is the page title. I am not sure how I can access that from the

    code
    > behind page. I also call a function that creates a css style sheet as well
    > as a function that creates my navigation bar for the web site. Is there a
    > way for me to get around the error without moving the code blocks? If not,
    > how can I implement the changes for the three problem areas?
    >
    >
     
    Jeremy Ames, Mar 4, 2004
    #4
  5. Jeremy Ames

    Jeremy Ames Guest

    What about the CSS? That is supposed to go into the head section of the
    page.

    "bruce barker" <> wrote in message
    news:...
    if you are framework 1.1,

    <title id=title runat=server>

    will showup on the codebehind as a generic html control, which you can set
    attributes or innerhtml.

    -- bruce (sqlwork.com)



    "Jeremy Ames" <> wrote in message
    news:#...
    > I have run into a major road block with my page development projects. I am
    > trying to add a literal control to my asp.net page and I got an error
    > stating that the control could not be added because of code blocks (<% %>)
    > on the page. Most of these blocks can be handled by adding a label control
    > to the form so it is not that big of deal, but one of the things being
    > posted is the page title. I am not sure how I can access that from the

    code
    > behind page. I also call a function that creates a css style sheet as well
    > as a function that creates my navigation bar for the web site. Is there a
    > way for me to get around the error without moving the code blocks? If not,
    > how can I implement the changes for the three problem areas?
    >
    >
     
    Jeremy Ames, Mar 4, 2004
    #5
  6. Jeremy Ames

    Peter Blum Guest

    When outputting javascript, Microsoft has supplied several methods on the
    Page object to properly place the code and avoid getting called multiple
    times. Look up RegisterStartupScript, RegisterClientScriptBlock,
    IsClientScriptBlockRegistered and IsStartupScriptRegistered on the Page
    class.

    I don't recommend using a Panel as a place to drop any controls unless you
    want its <div> wrapper. Microsoft provided the PlaceHolder control as a
    place to add other controls without getting any additional HTML.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "Jeremy Ames" <> wrote in message
    news:...
    > The literal that I am loading is Javascript. Will that work in a panel?
    >
    > "Cowboy (Gregory A. Beamer)" <> wrote in
    > message news:...
    > Try adding a panel and then adding the control to the panel. As I have not
    > worked with <% %> blocks, this is just a guess, but the panel makes a

    better
    > container for controls than Page, IMO.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > **********************************************************************
    > Think Outside the Box!
    > **********************************************************************
    > "Jeremy Ames" <> wrote in message
    > news:%...
    > > I have run into a major road block with my page development projects. I

    am
    > > trying to add a literal control to my asp.net page and I got an error
    > > stating that the control could not be added because of code blocks (<%

    %>)
    > > on the page. Most of these blocks can be handled by adding a label

    control
    > > to the form so it is not that big of deal, but one of the things being
    > > posted is the page title. I am not sure how I can access that from the

    > code
    > > behind page. I also call a function that creates a css style sheet as

    well
    > > as a function that creates my navigation bar for the web site. Is there

    a
    > > way for me to get around the error without moving the code blocks? If

    not,
    > > how can I implement the changes for the three problem areas?
    > >
    > >

    >
    >
    >
     
    Peter Blum, Mar 5, 2004
    #6
    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. James Doran
    Replies:
    2
    Views:
    628
    James Doran
    Jun 15, 2004
  2. Dylan
    Replies:
    5
    Views:
    444
    Daniel T.
    Mar 22, 2005
  3. Øyvind Isaksen
    Replies:
    1
    Views:
    1,030
    Øyvind Isaksen
    May 18, 2007
  4. Don
    Replies:
    0
    Views:
    152
  5. Giorgio Parmeggiani

    Adding a control to the DataGrid collection controls

    Giorgio Parmeggiani, Oct 9, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    208
    Jacob Yang [MSFT]
    Oct 22, 2003
Loading...

Share This Page