Subscribe to RSS Feed

C#, ASP.NET, and Your Mom

Getting Started with ASP.NET (Part 1): "Hello World"

So you want to develop web applications with ASP.NET? Fair enough. You've got a lot to learn, of course. There's some incredible technology running under the hood of each and every ASP.NET web application, and you're not going to understand all of it overnight. That said, once you do grasp the technology, you will have some incredibly powerful tools for rapid and robust web application development at your fingertips.

However, if you are like me, you'll want to jump in and learn the technology as you go. For this reason, I am putting together a series of articles to help you get accustomed to Visual Studio, ASP.NET, and the .NET framework as a whole. Basically, I'll show you what I wish I had when I was starting out. The infamous Hello World application is a good place to start. I'll show you three ways to accomplish this in ASP.NET

Okay, let's get started. Open up Visual Studio. I'll be using Visual Studio 2008 here, but 2005 will work as well. If you don't have either, you should download Microsoft's Visual Web Developer 2008 Express. VWD Express provides all the functionality we'll need to get through this series. The certainly are many differences between Visual Studio and VWD Express, but that's another article.

When your IDE of choice is open, create a new Project by opening the File menu, hovering your cursor over "New," and selecting "Project..." as shown below.

Click on "Project" under File -> New

On the dialog that pops up, select "ASP.NET Web Application", under the "Web" project type. Name the project "HelloWorld." A project is a unit of compilation, or, in other words, a container for the files you'll create for your application. Click the image thumbnail to view it at full-size.

 

Select "ASP.NET Web Application" as the project type and enter the name "HelloWorld."

At this point, the HelloWorld project will be created and the Visual Studio (or VWD) view will change. You will be presented with the contents of the "Default.aspx" file. Default.aspx is, as its name implies, the default page that will be shown for your application, much like index.html for a static HTML project. What you are viewing is ASP markup, which is a mix of ASP.NET tags and HTML. Since we don't know any ASP.NET code yet, let's switch to Visual Studio's WYSIWYG view, Design mode. You can switch to Design mode by clicking on "Design" at the bottom of the file editor.

Click "Design" to switch to Design mode

In Design mode, we see that we have an empty page (no, that's not en error - you have not added any content yet!) We're trying to show "Hello World!" to the world, and this is a WYSIWYG editor, so just type it in. The text should appear within the div tag, as shown.

Type "Hello World!" within the div tag

That's it! Let's start out application so we can see if it compiles and runs correctly. Select "Start Without Debugging" from the "Debug" menu.

Select "Start Without Debugging" from the Debug menu

You should notice that a popup message appears in your task bar noting that the ASP.NET Development server is running. This means that Visual Studio has started a service on your local computer that allows your computer to behave like a real webserver and host your application. It'll continue to run until we decide to end the runtime session, which, in our case, will end when we close Internet Explorer.

This dialog will be shown in your taskbar.

More importantly, Internet Explorer will open and display the Default.aspx page to us. Hopefully, it looks like this:

Our "Hello World' application running in Internet Explorer

Congratulations! You've just created and run your first ASP.NET web application. Excited yet? I hope so, because we've got more to cover here. Design mode is nice, but it doesn't always provide us with the granularity of control that we want when designing pages. Let's switch to Source mode, which is what we were started in originally. Do this by clicking "Source" at the bottom of the editor. Then, remove the existing "Hello World!" text. Replace it with the following code:

<%= "Hello World" %>

 

This is what's called an "inline expression." It is a type of ASP tag that inserts the value of the expression into the page at runtime. The quotes are necessary because we are providing a string expression. If they were omitted, it would try to evaluate them just like any other C# code. We will look at using inline expressions, other code render blocks, and examine the other ASP tags in another article. For now, ensure that your Default.aspx page looks like this one:

Switch to Source mode and insert the inline expression code

Run the application again by using the Start Without Debugging command. You're going to be using this a lot, so you should probably learn the keyboard shortcut for it (Ctrl+F5). Verify that "Hello World!" is shown again, and close Internet Explorer. Cool! Two out of three ways of showing "Hello World" down. Now, let's take a look at how we can combine Design mode and Source mode so we can get both a preview of our page and granular control over its contents. Visual Studio provides a way for us to view both at the same time. Click on "Split" at the bottom of the editor, as below, to switch to this mode.

Switch to "Split" mode

Next, we're going to look at the Toolbox. The Toolbox contains all of the nifty little toys that Microsoft has provided us with for developing our applications quickly. It's pretty extensive, and rightly so. Why should we have to rewrite code for features that are included in almost every web application? By default, the Toolbox (shown below), should reside to the left of the editor frame. You may have to click on a "Toolbox" button to get it to display, depending on your resolution.

The Visual Studio Toolbox

Each entry in the Toolbox is called a control, and the controls run the gamut from displaying text, to providing a file upload feature, to handling user login. Each control can be dropped into your page (into either the Design window or the Source window), and then configured to match your needs. We're interested in display text here, so double click on the Label control. Visual Studio will insert a label control at your cursor. Notice that you can see both the ASP tag representing the Label in Source mode and the appearance of the Label in Design mode. It should look like this:

A Label control shown in Split mode

If you click on the Label in the design window, we'll see another important Visual Studio pane: the Property Editor. By default, this is shown in the bottom-right corner of the IDE. The image below highlights a few things you should notice about the property window. When the Label is selected, its name is shown in the first line of the Property Editor. Likewise, its properties are shown for direct editing. The Text property is highlighted, and its value is Label. Looking at the tip displayed, we see that the Text property represents the text that the label shows. Ah-ha! It is currently set to "Label," so that is why Design mode shows what it does. Let's change that to "Hello World!" as shown (quotes not required here - Visual Studio will insert them for us.)

Text property of our Label editted to "Hello World!"

Notice that Visual Studio updates both our Design and Source views to show the new value of the Text property for Label1. Run this application one final time to verify that it works. If you've forgotten the keyboard shortcut, I'll remind you that it's Ctrl+F5, but don't let it happen again!

So, we've gotten our Hello World application running three different ways (pure HTML, inline expressions, and the Label control), and learned the basics of moving around within Visual Studio. Like I said, we've got a lot of ground to cover still, but this is a good start. This was an image-heavy post, but that was appropriate for your first tutorial. Please don't expect them all to be like this. In future articles, I will use less images, but I am as-wordy, at the very least. Please feel free to post any questions you have.

Next article: Getting Started with ASP.NET Part 2: Code-behind and Events >>

  • Share/Save/Bookmark

Comments

  • Raul Roa said:

    You should add Response.Write("Hello World!"); on the Page_Load event to the list.

  • Josh Jordan (Author) said:

    This is true, but I didn't want to introduce the concept of code-behind in this article. I was going to start the next entry in the series with some simple events, and that sounds like a great way to start. Thanks for the suggestion!

  • Stephen Forcucci said:

    Clipboard in step 2 doesn't work - well, it works, but the " (quotation marks) it uses don't appear to work when directly pasting it into VWD. Works fine if you delete and retype them or just type the whole thing in manually.

  • Josh Jordan (Author) said:

    Ah, I see the problem. When the article is published, the quotation marks are processed and "beautified" into directed quotation marks, as in the title of article. I solved this problem by using the HTML character code for quotation marks. This is a bit frustrating - I'll have to remember to do this in future articles.

    Thanks for the heads up.



Recent Archives
1 24 vintage marx slot crystorama royal flush mount 100 hand video poker download free bonus keno thepokerguide games eva vig contract type per line item free bonus mulit payline slots shotgun straight up awp drug pricing bacardi baccarat decanter millennium rum 100 islands poker run seebeforeyoudie.net 1790 s food crap strayer.info buy video poker games sctravel.net batman dark knight wallpaper joker oscn.org 1985 vw joker pirate treasure jewels rob thomas street corner symphony plantcultures.org 1-1 2 wr galvanized roof deck nominal amp per line formula casino on line with bonus slots card credit high people risk bangmyindianwife.com blue sky blue sport fruit punch blue dot jackpot winner ann kennedy full house resort royal flush industries inc 2 deck blackjack in aruba 72-ton the joker 100 plastic poker cards south africa back masage leads to hand job 10 dollar deposit minimum online casinos bulldog bucks card midland high school computer game poker share video ware idol contestant sings paula straight up alien gaming machines bmc remedy wild card 1 gallon flush toilet queen jewels sweden aaaokwebmember.com century twenty one seymour in braless pokies 2007 jelsoft enterprises ltd let it ride bachman overdrive clifford the big red dog game aristocrat 50 lions pokies game download ameristar casinos omaha ne 12 tube poker chip tray aztec gaming machine 1 club casino nd bonus coupon 5 cent roulette high or low impedance back in gods hand three kinds of fuels erection straight up gastonia century twenty one aces and jokers houses for sale century twenty one crusty demons the hard way let it ride bto champagne and sherbert fruit punch recipe burns supper croupier queens jewels game brochure five first saturdays devotion free full house md episodes wild deuces acompa antes san gil blguitar.com royal flush band backgammon big six learning free bonus feature slots only chocolate red pussy dogs free wild card keno download full tilt poker bonus code 1 2 inch foam dice baccarat candle fighting squadron one twenty four moonlighters gocabins.com different ways to build a house first five books of hebrew bible 2006 victory jackpot casino bonus poker games 3 line video poker 50 play video poker strtegy card credit high processor risk princetonnationalsurveys.net 52 cards plus joker 1 43 scale slot cars forever twenty one atlanta nexi.com baccarat back-gammon-online three kinds of symmetry alex kingston croupier nude effinghamcounty.org clifferd the big red dog balsamic vig nola is acid ph high or low deuces wild video poker payout in4mador.com handheld bonus poker game boston red dogs candid teen bikini pokies all that crap at school 3pt root rake chet baker the hard way album 1995 waverunner 1100 flush kit gate way profile 3 hard drive circus by the sea my way frank sinatra hard cover redlightemail.com alian ante farn fast way to lose weight successfully back of your hand guitar tab mineweb.co.za giada de laurentiss pokies first five huracanes in 2004 let it ride strategy adsneeze.com big six naacp air anime christian crap spellspot.com alabama high school report cards free vig tits 777 online gambling 1924 studebaker big six duplex phaeton 1 1 2 inch flush pull .8 gallon flush toilet vast aire deuces wild ron vig cytonox triple berry fruit punch best way to clean a house all casinos in florida black jack video poker gambling 3 the hard way jim brown worden.com 1 1 2 galvanized metal deck three kinds of plate boundaries audio clips of the joker $1.00 minimum deposits online casinos pot of gold gaming machines georgia baccarat acessories three kinds of spyware all the crap i do mp3 betting line per nfl fruit punch for a party best way to claim lotto jackpots arnold snyders blackjack half way house decatur al full episodes of house online official western big six conference statistics reformat address list one per line absolute poker reload bonus codes best way to air a house credithelpexpert.com big six accounting firm jokes 1 red dice bcfls.org against backgammon computer play poker onlinefreerolls bonus gamingonlinewin party poker bonus code no deposit 2007 victory vegas jackpot jackseattle.com batman beyond the joker acompa antes merida mexico card high counting blackjack ante bellum etymology acompa antes independientes en bogota pcl.com croupier job croupier uddannelse jackson five first album awp inflation by astra zeneca aw crap pictures 1970 sylvan pontoon auto money download free back hand spring on the beam all that david copperfield kindof crap adam faith and the roulettes acompa antes guadalajara mexico a picture of joker form batman charlotte video poker adult sex roulette age for gambling stockholmwisconsin.com harley deuces wild license plate bette midler jackpot dvd too high or too low tsh croupiers casino lac leamy 2 gb high speed sd card 007 casino royale quotes australian actor played joker bellevue iowa pirate treasure storey 10 blank decks skateboard decks club twenty one realty astuce roulette baby books first five years 10 person folding poker table backgammon bear off rules 1 24 scale slot cars bodies beat casino in online roulette scam equinoxfitness.com 2010 bingo sites nickelback song learn the hard way best ways to burn fat fast usb video cards cause slow down peeingclips.net bring it on keno apps for blackjack corner of a street queens jewels pearl clasp 1 32nd scale slot cars big six and super three 1985 vw westfalia joker southeastern lefthand corner of main street full columbia house movie list affiliate best gambling 4 x 4 bingo grid clifford the big red dog activities about internet gambling cheapest way to heat a house tennesseetrustee.com adjustable lawn rakes louisville slugger hands back advanced craps yourmilfporn.com ben vig ballarat pokies how to make caribbean fruit punch ameristar casinos kansas city inforadionet.com fruit machines free online all jackpot casino promotion code deuces poker strategy video wild xpressnet.com three kinds of love movie quote 110 tricks svengali deck carthage central high school report card antique 3-in-1 roulette acura 3.2 engine is crap 17th european backgammon championships gay pick up straight guy awp governance arrangements uk jane krakowski pokies bonuscode onlinetournament keno blackjack abbotsford bingo hall in canada 16mm razor edge white dice american idol wild card winners a blackjack 1978 ford f350 stake rake queen art jewels backgammon board game rule 2006 victory cory ness jackpot bar le full house magog rallyformusic.com 14g real clay poker chips 1100stx flush directions cooling system boston red sox dog jackets owasso.com cole bothers circus of the stars jessica-alba-naked.com fast way to lose fat backgammon agourahills can dogs see red acompa antes colombia fast way to burn calories ancient pirate treasure authorized vgt gaming machine servicers free bonus round slots card diet high low protein baccarat 250d 250a 1 32nd scale slot cars cold case files bonus game backgammon acey ducey rob thomas street corner syphony haiku number of syllables per line biblefacts.org roman vig amusements fruit machines 21 dice game rules back hand job armenia backgammon backgammon basics 1 24 slot car speed tricks rita vig ace point backgammon budget free claims money state fox house full episode age requirment for michigan casinos bonus code poker stars veryfunnycartoons.com 1 32 artin slot car all california casinos rob thomas street corner symphony first five presidents test 100 hand poker cliferd big red dog apple casinos facorelogic.com ama big six racing cinoche.com 4,5,6 dice game downloads free poker strip video addtron awp 100 driver good vig best celebrity nipples or pokies photos ante a libro firenze cheap ways to build a house 10 x 10 deck kit yapclub.com free slots bonus game per 6 cell line 115 poker chips jediknight.net formula twenty one duderanch.org its hard to find a way deuces wild basic strategy 1957 ferrari testerosa pontoon fender corner street plymouth ma no deposit bonuses slots bankruptcy free money creative ways to swap houses six pack and big white cock ad ante deluvian nd bonus slots wholovesmoney.com always win at roulette ice t straight up free bonus slot games pirate treasure activities for kids freefarmsex.net fast way to kill lawn donnaskorner.com batman and jokers relashionship 3rd war keno valentino croupier terms drop per foot sewer lines 40 the hard way dvd batman beyond return of the joker alicia rhodes seven the hard way age gambling aruba 6d dice download free game poker video baccarat bird ass striping games without blackjack alabama awp settlement dangerous ways to lose weight fast cherrymaster fruit machine hacking can dogs eat red licorice glaciermt.com 2007 blackjack ford mustang are stock markets costly casinos pirate treasure activities for kids century twenty one new jersey 1994 185 lowe pontoon ernrcr3.com