Adding controls to Page.Controls collection

J

Jeremy Ames

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?
 
C

Cowboy \(Gregory A. Beamer\)

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!
**********************************************************************
 
B

bruce barker

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)
 
J

Jeremy Ames

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

message 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!
**********************************************************************
 
J

Jeremy Ames

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

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)
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top