By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,589 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,589 IT Pros & Developers. It's quick & easy.

Outputting text when using code behind?

P: n/a
I have a major doubt about outputting text in ASP .NET when using code
behind.

I know most of the output you gain from a code behind file (.aspx.cs) is
outputted to the Webform (.aspx) using labels, datagrids, datalists...
Also, I know you can output directly using Response.Write(). But this places
the output at the beginning of the file.

How can you output the text at a specific place in the HTML code? An example
would be when building a menu on a website and you retrieve the items from a
database using the code in a code-behind file.
I'm guessing that the solution solution has to be something like inserting a
custom tag into the aspx.cs file which will be replaced with the output
controlled from the aspx.cs file.

Thank you for your support.
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I believe you are talking abut using User Controls (ascx files). User
control are placed inside aspx page (via custom tags) and have their own
rendering logic (this also makes them reusable inside an application).

Check out:
http://www.dotnetjunkies.com/quickst...bpagelets.aspx

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl...
I have a major doubt about outputting text in ASP .NET when using code
behind.

I know most of the output you gain from a code behind file (.aspx.cs) is
outputted to the Webform (.aspx) using labels, datagrids, datalists...
Also, I know you can output directly using Response.Write(). But this places the output at the beginning of the file.

How can you output the text at a specific place in the HTML code? An example would be when building a menu on a website and you retrieve the items from a database using the code in a code-behind file.
I'm guessing that the solution solution has to be something like inserting a custom tag into the aspx.cs file which will be replaced with the output
controlled from the aspx.cs file.

Thank you for your support.

Nov 18 '05 #2

P: n/a
You can place a Literal Tag on the aspx page, and set the text value to be
anything you like.
Very much like a Label.

Alternately you can make a Control which retrieves the data in its own code
behind and this can be placed anywhere on your page.

"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl...
I have a major doubt about outputting text in ASP .NET when using code
behind.

I know most of the output you gain from a code behind file (.aspx.cs) is
outputted to the Webform (.aspx) using labels, datagrids, datalists...
Also, I know you can output directly using Response.Write(). But this
places the output at the beginning of the file.

How can you output the text at a specific place in the HTML code? An
example would be when building a menu on a website and you retrieve the
items from a database using the code in a code-behind file.
I'm guessing that the solution solution has to be something like inserting
a custom tag into the aspx.cs file which will be replaced with the output
controlled from the aspx.cs file.

Thank you for your support.

Nov 18 '05 #3

P: n/a
So every part of a website should be coded using different user controls?
For the menu I should use one user control, for the latest news box another
user control and so on?

Oh, and do you know some example website source code available which I can
download?

Thank you for your answers.

"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl...
I have a major doubt about outputting text in ASP .NET when using code
behind.

I know most of the output you gain from a code behind file (.aspx.cs) is
outputted to the Webform (.aspx) using labels, datagrids, datalists...
Also, I know you can output directly using Response.Write(). But this
places the output at the beginning of the file.

How can you output the text at a specific place in the HTML code? An
example would be when building a menu on a website and you retrieve the
items from a database using the code in a code-behind file.
I'm guessing that the solution solution has to be something like inserting
a custom tag into the aspx.cs file which will be replaced with the output
controlled from the aspx.cs file.

Thank you for your support.

Nov 18 '05 #4

P: n/a
there are tons of sample out there

http://www.gotdotnet.com/ is a great one

Otherwise just search for whatever you want in google.

i.e.
ASP.NET control example

"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:eu**************@TK2MSFTNGP15.phx.gbl...
So every part of a website should be coded using different user controls?
For the menu I should use one user control, for the latest news box
another user control and so on?

Oh, and do you know some example website source code available which I can
download?

Thank you for your answers.

"Andrei Pociu" <an**********@geekpedia.com> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl...
I have a major doubt about outputting text in ASP .NET when using code
behind.

I know most of the output you gain from a code behind file (.aspx.cs) is
outputted to the Webform (.aspx) using labels, datagrids, datalists...
Also, I know you can output directly using Response.Write(). But this
places the output at the beginning of the file.

How can you output the text at a specific place in the HTML code? An
example would be when building a menu on a website and you retrieve the
items from a database using the code in a code-behind file.
I'm guessing that the solution solution has to be something like
inserting a custom tag into the aspx.cs file which will be replaced with
the output controlled from the aspx.cs file.

Thank you for your support.


Nov 18 '05 #5

P: n/a
Andrei,

One more thought: you can use a "placeholder" control when you *know* where
you want something to go, then add to that control at runtime, e.g. (vb
syntax)

dim uc as new MyLabel
MyPlaceHolder.controls.add(uc)

Literals have a place, but I find the syntax of using placeholders easier to
swallow.

Re user controls, I use them extensively for a few main reasons: 1) Easy way
to reuse code within the site or across sites, 2) Unclutters the geography of
the page and 3) Easy to turn them off or swap them out at run-time (e.g. a
single "visible=false" can turn off a whole chunk of the ui). Other reasons
people use them is that they can be cached independently, and you can modify
them without redeploying the whole project.

hth,

Bill

"Andrei Pociu" wrote:
I have a major doubt about outputting text in ASP .NET when using code
behind.

I know most of the output you gain from a code behind file (.aspx.cs) is
outputted to the Webform (.aspx) using labels, datagrids, datalists...
Also, I know you can output directly using Response.Write(). But this places
the output at the beginning of the file.

How can you output the text at a specific place in the HTML code? An example
would be when building a menu on a website and you retrieve the items from a
database using the code in a code-behind file.
I'm guessing that the solution solution has to be something like inserting a
custom tag into the aspx.cs file which will be replaced with the output
controlled from the aspx.cs file.

Thank you for your support.

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.