Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Each time you create a brand new ASP. NET web form page, you can select either a page with scripting or a page with the code file and you can make your choice of programming language. In this demonstration, I'll create a page with a separate code file and this time I'll use Visual Basic. I'm still working in the website CreatePages that I opened previously. From the menu, I'll select Website > Add New Item. I'll select Web Form from the Templates list and this time I'll set the name as PageWithCodeFile and set the Language to Visual Basic.
I will select the option Place code in separate file and click Add. Because I have said I want it to create a separate code file, Visual Web Developer created both the ASPX file and the associated file PageWithCodeFile.aspx.vb. If I rename the primary file, Visual Web Developer will rename the associated code file for me. It also manages this attribute, the CodeFile attribute, which is built into the header of the page. This is how the two files are linked together.
Now I'll go through essentially the same set of steps I did in a previous video. I'll add a title. I'll click into the Title element in the Head section and type in the text PageWithCodeFile. I'll click into the div tag section. I'll add an h1 tag set and type in the same text and then I'll go into Design view. In Design view, I'll press Enter, I'll go to the Toolbox panel and I'll drag in a Label control. I'll place it inside the new paragraph and then I'll go to the Properties panel, scroll down, find the ID property and change the ID of the label to myLabel. I'll then click right after the Label control and press Enter. Go to the toolbox and drag in a Button control, with the Button selected I'll change its Text property to Click me and then I'll double-click on the Button control.
This time the event handler function is created using the Visual Basic language and it's created in the separate code file, PageWithCodeFile.aspx.vb. As in the previous exercise, I'm going to be executing this code on the server. So I'll execute the following code. I'll type in the beginning of the ID of the control myLabel. Then press the dot character. Visual Web Developer auto completes the ID of the control and then I'll select the Text property and press the spacebar and then I'll put in the equal assignment operator which is the same for Visual Basic as it is for C# and I'll type in the text "Executed at server".
This time I won't put in the semicolon because I'm working in Visual Basic, which doesn't use that character to terminate a statement. I'll go back to the page and save the changes by pressing Ctrl+S. Then I'll go to the menu and select Debug > Start Without Debugging. When the page first appears, it displays the initial value of the Label control, simply Label and when I click the button that results in posting the page to the server and the Label control shows the text "Executed at server".
So you are using essentially the same sort of code. The Button control dispatches a click event. You react to the click event by executing server-side code, which modifies the values of various other Web Form controls. What differs between pages is which language you are working in and whether you have build your pages using code in the page or using an associated code file. Throughout the rest of this video series, I'll be using pages with associated code files. I prefer to keep my HTML code in one file, and my scripting code in a separate file and I think you will find that that's the best way to create your own websites. It makes it very easy to know what kind of code you're working with at any given point and it reduces the amount of scrolling up and down you have to do, when you are doing your coding, when you need to make changes or fix your bugs.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97526 Viewers
61 Video lessons · 84763 Viewers
71 Video lessons · 68945 Viewers
56 Video lessons · 101390 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.
Your file was successfully uploaded.