Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2005, 12:07 AM
Registered User
 
Join Date: Dec 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting variables into aspx pages dynamically.

How do I insert a variable in my code-behind file into the aspx page dynamically?
i.e
Code BF:
public string a = "inserted text";

aspx file:
<body bgcolor="!variable a goes here!">

 
Old December 19th, 2005, 08:45 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Make the body tag accessible to the server side code with the runat attribute:

  <body runat="server" id="tagBody">

Then, in your codebehind, you do this:

  protected System.Web.UI.HtmlControls.HtmlGenericControl tagBody;

Then you can access the body tag and do anything on the control such as assigning an attribute:

  tagBody.Attributes["bgcolor"] = "inserted value";

-Peter
 
Old December 19th, 2005, 04:49 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Peter, cool piece of coding. I always wondered how to change the bgcolor from the codebehind.

Jim

 
Old December 20th, 2005, 08:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can do that kind of thing with any tag that's brought into context in the codebehind. You can also add attributes that aren't even normally there and use those values in client side script. With the flexibility of the javascript and browser object models you'd be amazed at what you can cook up.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically include an aspx page ndkicha_1981 General .NET 0 October 19th, 2007 03:12 AM
generates aspx pages dynamically and compile also shadab_17 ASP.NET 1.0 and 1.1 Professional 0 February 28th, 2007 02:35 AM
getting asp variables dynamically marco_1 Classic ASP Basics 13 December 11th, 2006 05:39 PM
Dynamically inserting images in the report ashu_from_india Crystal Reports 0 February 22nd, 2005 12:46 PM
aspx - dynamically expanding the page vhrao General .NET 1 November 5th, 2004 03:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.