Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 June 8th, 2006, 02:23 PM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default What is this?

I've seen code where it contains things like "{0}". I know that data fills those spots and replaces the characters but how does it do this? Some code examples and explanations would be perfect. I would search on google for it but I don't even know what it's called.

Thanks.

 
Old June 8th, 2006, 02:30 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It depends on where you see it. Some controls, like the GridView use it for formatting data. This is done inside the controls.

You can also use it your self, in combination with String.Format:

Dim message As String = "Hello {0}, the time is now {1}"
Label1.Text = String.Format(message, txtUserName.Text, DateTime.Now.ToString())

The String.Format function takes a string, and a number of arguments that map to the {} placeholders inside that string. You need one for each unique {} combination, although it's possible to use the same placeholder more than once in a string.

I think the term to search for is string formatting....

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Open Your Arms by Editors (Track 10 from the album: The Back Room) What's This?
 
Old June 8th, 2006, 03:31 PM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, ok. Thank you for the help.

How could I take this and make a database driven page title, for example?

 
Old June 8th, 2006, 03:36 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Exactly the same:

1. Add a title your page like this:

Title="Welcome to the page {0}"

2. Somewhere in code:

Me.Title = String.Format(Me.Title, SomeDatabaseDrivenValue)

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 8th, 2006, 03:43 PM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Me.Title isn't working. This is ASP.NET 1.1 right?

 
Old June 8th, 2006, 03:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Sorry, no. Me.Title is ASP.NET 2. Somehow I was assuming you were using ASP.NET 2.

In .NET 1.x, you can make the title runat="server" and add a declaration for it in the Code Behind as an WebControls.Literal control.

<title id="lblPageTitle" runat="server" />

Then you can set its Text property programmatically.

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 8th, 2006, 04:08 PM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had to declare it as an HtmlGenericControl and set the InnerText property but regardless thank you. I've been wondering about both of these things for a while.

 
Old June 8th, 2006, 04:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You are absolutely right. I copied this from an existing application that has both a dynamic title and a literal called lblTitle.... I copied the wrong parts into this message.

Sorry for the confusion, but glad it's working...

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004









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