Insert same information many times

S

sfxpete

Hi!

Heres something thats been bugging me but I don't seem to be able to
find an elegant way of solving the problem....

I'd like to have a small amount of dynamic text (its actually a string
sucked in from the appsettings section in the web.config) appear in
various locations on a webpage (NOT part of a recordset etc). In this
case its a brandname for the site.

So, I want to just intermingle the brand name in the pages text where
it suits. If I changed brand no probs I just change my config and the
whole site adjusts to suit.

I know of two ways to do it...

A. Use a lot of asp.net label or literal controls and then set each
one individually in the code behind. This just looks ugly and isn;t
the best to maintain.

B. Use an inline expression and call a function that returns the
brandname. A better solution but from what I know (it isn;t much!)
that starts to go back to old classic ASP although by just calling the
function the code is still isolated to the code behind...

I was thinking of a control collection or something that I can iterate
through. I guess my base question is whats the best way to perform
the task at hand!

Sorry about the waffling..... I love waffles.... :)

Cheers
 
1

1388-2/HB

I was thinking of a control collection or something that I can iterate
through.

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.
 
S

sfxpete

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.

Thanks for the help, like the custom control idea. Never even occured
to me to do it that way! Just out of interest can anybody give me a
good reason not to use an inline expression in this instance otherwise
I'm forced to put in a label wether it is a custom one or one thats
comes with asp.net and that means the hassle of giving them nice names
for everyone and on every page. In this case that could mean me
inserting over 100-125 controls and having to name them nicely! Or is
this just a side effect of the all the advantages I will have from
using them? It must be noted that I'm fairly new to asp.net and come
from a asp background.

Cheers guys (and girls!)
 
S

sfxpete

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.

Thanks for the help, like the custom control idea. Never even occured
to me to do it that way! Just out of interest can anybody give me a
good reason not to use an inline expression in this instance otherwise
I'm forced to put in a label wether it is a custom one or one thats
comes with asp.net and that means the hassle of giving them nice names
for everyone and on every page. In this case that could mean me
inserting over 100-125 controls and having to name them nicely! Or is
this just a side effect of the all the advantages I will have from
using them? It must be noted that I'm fairly new to asp.net and come
from a asp background.

Cheers guys (and girls!)
 
S

sfxpete

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.

Thanks for the help, like the custom control idea. Never even occured
to me to do it that way! Just out of interest can anybody give me a
good reason not to use an inline expression in this instance otherwise
I'm forced to put in a label wether it is a custom one or one thats
comes with asp.net and that means the hassle of giving them nice names
for everyone and on every page. In this case that could mean me
inserting over 100-125 controls and having to name them nicely! Or is
this just a side effect of the all the advantages I will have from
using them? It must be noted that I'm fairly new to asp.net and come
from a asp background.

Cheers guys (and girls!)
 
S

sfxpete

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.

Thanks for the help, like the custom control idea. Never even occured
to me to do it that way! Just out of interest can anybody give me a
good reason not to use an inline expression in this instance otherwise
I'm forced to put in a label wether it is a custom one or one thats
comes with asp.net and that means the hassle of giving them nice names
for everyone and on every page. In this case that could mean me
inserting over 100-125 controls and having to name them nicely! Or is
this just a side effect of the all the advantages I will have from
using them? It must be noted that I'm fairly new to asp.net and come
from a asp background.

Cheers guys (and girls!)
 
S

sfxpete

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.

Thanks for the help, like the custom control idea. Never even occured
to me to do it that way! Just out of interest can anybody give me a
good reason not to use an inline expression in this instance otherwise
I'm forced to put in a label wether it is a custom one or one thats
comes with asp.net and that means the hassle of giving them nice names
for everyone and on every page. In this case that could mean me
inserting over 100-125 controls and having to name them nicely! Or is
this just a side effect of the all the advantages I will have from
using them? It must be noted that I'm fairly new to asp.net and come
from a asp background.

Cheers guys (and girls!)
 
S

sfxpete

Sounds like a good excuse to play with custom controls.

One way to tackle your problem is to make a custom Label control that
initializes it's text from the web.config file automatically. Then, instead
of inserting regular, blank Labels and iterating thru them, insert your
custom Labels and you're done.

On the iteration front you've got Page.Controls and Page.FindControl at your
disposal to find just about any control you add to a page.

Thanks for the help, like the custom control idea. Never even occured
to me to do it that way! Just out of interest can anybody give me a
good reason not to use an inline expression in this instance otherwise
I'm forced to put in a label wether it is a custom one or one thats
comes with asp.net and that means the hassle of giving them nice names
for everyone and on every page. In this case that could mean me
inserting over 100-125 controls and having to name them nicely! Or is
this just a side effect of the all the advantages I will have from
using them? It must be noted that I'm fairly new to asp.net and come
from a asp background.

Cheers guys (and girls!)
 

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

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top