Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old April 8th, 2012, 10:45 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2010
Location: Hyderabad, India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use constants in ASP.NET 3.5

I am regular programmer in traditional ASP, but now turning to program in ASP.NET 3.5. My requirement is defining few constants about 20 of them of different types:
Strings, integers, datetime etc. In traditional ASP, I used to define them in a single file
Example abc.asp
In each application file, I used to include the abc.asp file as
<!--#include file="nsns5DBCONN.asp"-->
and use the constants.

Dim dtdldate,inthseries, strvenue
dtdldate= #6-5-2010 4:00:00 PM#

I want to do the same in ASP.NET 3.5. I created a file myconstants.cs
In App_code folder.

public class myconstants
public myconstants()


Please let me know how proceed from now.
I want to know how to define the above 3 different types of constants
And how to use them in individual application aspx files. I want the code in both C# and VB.
Reply With Quote
  #2 (permalink)  
Old April 8th, 2012, 11:00 AM
Imar's Avatar
Wrox Author
Points: 71,611, Level: 100
Points: 71,611, Level: 100 Points: 71,611, Level: 100 Points: 71,611, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,008
Thanks: 79
Thanked 1,575 Times in 1,552 Posts

Hi there,

Since this is not directly related to my book, please post questions like these in a more general ASP.NET category from this list: http://p2p.wrox.com/asp-net-asp-12/ This way, you'll attract more viewers.

That said, your code is almost done; just define the constants in your class:

using System;
public class MyConstants
  public const int    inthseries=8000;
  public const string strvenue = "zzzzzzzzz";
You then use them in your code as follows:

string whatever = MyConstants.strvenue;

You can't declare DateTime as a constant so, depending on how you need it, you need to look at alternatives.

I want the code in both C# and VB.
Yes sir. Right away sir. Anything else sir? Can I get you some coffee?

In other words, this is not how it works. We're here to help you but we're not your servants. This is basic code so you should be able to convert from C# to VB yourself. If not, helpful converters are available: http://converter.telerik.com

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Constants: Where do they go? DragonLEG BOOK: Beginning ASP.NET 4 : in C# and VB 1 June 11th, 2011 02:02 PM
Changing Constants within a session mat41 Classic ASP Basics 2 August 27th, 2009 12:11 AM
declaring constants and pointer constants proslambano BOOK: Ivor Horton's Beginning Visual C++ 2005 3 March 6th, 2007 02:32 PM
Constants in XSL austinf XSLT 2 August 29th, 2006 06:04 AM
DriveType constants fordrs3 Beginning VB 6 1 June 22nd, 2003 08:23 AM

All times are GMT -4. The time now is 02:10 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.