Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The two primary languages that are used in ASP.NET, Visual Basic.net and C# are syntactically very different from each other. But they both use the underlying .NET Class Library, the set of components that enable your web applications. When you are first learning a programming language, it's useful to have a testing environment. A simple application to which you can add arbitrary code, and to displays the result of running that code. In this chapter, I demonstrate how to use critical aspects of the two programming languages. This is what the web form page looks like. It has a heading, a textbox and two buttons labeled Run Code and Clear Console. Let's take a look at the source code.
I'll open the code up to full screen by pressing the keyboard shortcut, Alt+Shift+Enter. Notice that within the form, there are two panels. A panel is a server-side control that translates as a div tag. So you can easily force content to be stacked one on top of another. With in the first panel, there is the textbox with a text mode attribute of MultiLine. This allowed the textbox control to display multiple lines of text. And then within the second panel there are two buttons with ids of runButton and clearButton, and they each have an onClick event handler that runs a function.
So each time the output function is called, it will add the line to the textbox and then go down to the next line. In the current version of the C# page, the runButton_Click function calls this function output, and passes in a value of Hello world, and then when the user clicks the clearButton the text property of the textbox is set to a blank string. So that's all the code in our testing environment. Let's give it a try. I'll run the application without debugging. I'll click the Run Code button a few times. And you'll see that each time I click the button, I'm appending a value to the existing textbox controls text property, and then when I click Clear Console that results in clearing the textbox.
Now I'm going to be using this page as the base for all of my exercises. So before I leave it, I'm just going to go back to the runButton_click function and I'm going to remove the call to the output function. And this will be the base file that I copy for each exercise. Now, I'll close that file and I'll press Alt+Shift+Enter again so I can see my panels, and I'll open up the Visual Basic version. Let's take a look at this one in full screen. The Markup code in the Visual Basic version is exactly the same. It has the same two panels. The textbox and the two buttons. The Ids are the same, and the click events are the same. But notice that the syntax of the scripting code is a little bit different.
In Visual Basic, a function that doesn't return a value is called a sub or a subroutine. The subroutine output is marked with protected sub at the beginning and the end sub at the end. The code within the function is almost exactly the same as the C# version. The exception is that there is no semicolon at the end of the line. I'm still however using Environment.NewLine to represent a character return line feed combination. The runButton_Click event still calls the output function, passes in a text value of Hello world and the clearButton_Click event still sets the text property to a blank string. I'll run this version of the page, without debugging. I'll test it by clicking the Run Code button a few times, and I'll clear the console. Then I'll close the page as with the C# version, I'll remove the call to output from the click event, so that I can use this as the base page for all of the other exercises in this chapter.
So if you don't have access to the Exercise Files, create your version of this page, using the code that I've displayed on the screen, and then for each exercise make a copy of that page, so that you can go through that particular exercise.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 100111 Viewers
56 Video lessons · 113145 Viewers
71 Video lessons · 82010 Viewers
131 Video lessons · 39347 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.