Saturday, October 15, 2016

Creating First Program in ASP.NET

                                                    
               Today we will do our First program in asp.net using visual basic.net language visual stdio 1: The first step we should open Visual studio from start menu then from the IDE click on new website as shown in figure 2-2.  
Creating First Program in ASP.NET
figure 2-2

Today we will do our First program in asp.net using visual basic.net language visual stdio 1: The first step we should open Visual studio from start menu then from the IDE click on new website as shown in figure 2-2

Creating First Program in ASP.NET
FIGURE 2-3

2: The first thing we will select visual basic language and select the asp.net empty website and chose your save location on the browse button.

3: click on OK button
4: The new windows should open look like this as shown in figure 2-3



figure 2.4

5:Right Click On the website in the solution explorer click on add from menu and select new webfrom from there and give name your webfrom whatever you want and hit the add button


6:And new screen will appear look like this as shown in figure 2-4 bellow.





explanation:-
You probably can’t wait to get started with your first ASP.NET website, so instead of giving you a theoretical overview of websites in VS, the next Try It Out exercise dives right into the action and shows you how to build your first web project. Then, in the How It Works explanation and the section that follows, you get a good look at what goes on behind the scenes when you view an ASP .NET page in your browser.

1. Start Visual Studio from the Windows Start menu or Start screen. For VSEW, the menu item is called VS Express 2013 for Web. For Windows 8.1, you’ll need to click the down arrow on the Start screen to go to the list of all applications. If you’re using the commercial version of Visual Studio, just start Visual Studio 2013 from the Start screen; all web-related components are accessed from the main VS program. You’ll be greeted by a dialog that lets you sign in to Visual Studio with a Microsoft account. This is useful if you want to synchronize your settings across multiple machines. Click Sign In to enter your credentials or sign up for a new account. If you don’t want to sign in, click Not now, maybe later. The first time you start VS, there might be a delay before you can use it because it’s busy configuring itself. Subsequent starts of the application will go much faster.
2. If you’re using a commercial version of Visual Studio, you may also get a dialog box that lets you choose between different collections of settings the first time you start Visual Studio. The choice you make on that dialog box influences the layout of windows, toolboxes, menus, and shortcuts. Choose the Web Development settings because those settings are designed specifically for ASP .NET developers. You can always choose a different profile later by resetting your settings, as explained later in this chapter.
3. Once VS is fully configured, you see the main screen appear, as shown in Figure 1-3. You get a full description of all the windows, toolbars, panels, and menus in the next section, so
for now, just focus on creating a new website. Click the File menu in the upper-left corner and choose New Web Site.If you’re using a commercial version of Visual Studio, depending on the settings you chose when starting Visual Studio the first time, you may have to open the submenu New first. Make sure you don’t accidentally use the New Project menu, because that is used to create different types of .NET applications. 

The New Web Site dialog box appears as shown in Figure 1-4.



4. In the middle of the dialog, above the list of the available templates, select .NET Framework 4.5.1 from the drop-down list. Then, in the Installed Templates section on the left, you can choose a programming language you will use for your site. This book shows all examples in both Visual Basic and Visual C# so you can choose a language to your liking.

5. In the list of templates in the middle, click ASP.NET Web Forms Site. Verify that File System is the selected option in the Web Location drop-down list at the bottom left. If you want, you could change the location on disk where the website is stored by clicking the Browse button and choosing a new location on your computer’s hard drive. For now, the default location — a folder under your Documents folder — is fine, so you can leave the location as is.

6. Click OK. VS creates a new website for you that includes a number of files and folders (see Figure 1-5) to jump-start your website.

7. Open the file Default.aspx by double-clicking it and remove all the code inside the <asp:Content> block that has its ID set to BodyContent (it starts with <div> at line 5 and ends with </div>) all the way at the bottom. Replace it with the following
bolded code:
--------------------------------------------------------------------------------------------------------------------------
<asp:Content runat="server"ID="BodyContent" ContentPlaceHolderID="MainContent">
<h2>Hello World</h2>
<p>Welcome to Beginning ASP.NET 4.5.1 on <%: DateTime.Now.ToString() %></p>
</asp:Content>
--------------------------------------------------------------------
You’ll see code formatted like this a lot more in this book. When you are instructed to type in code formatted like this with some code in bold, you only need to type in the bolded code. The other code should already be present in the file. Don’t worry about the code with the angle brackets (<>) and percentage symbol in the welcome message; these are called tags, and you learn more about them later. Although this code may not look familiar to you now, you can probably guess what it does: It writes out today’s date and time.

8. Press Ctrl+F5 to open the page in your default web browser. You see a page similar to the one shown in Figure 1-6.





If you already have some experience with Visual Studio you may be used to pressing F5 instead. If you use that option, the site is opened in debug mode and you may get a dialog asking if you want to enable debugging (which you can safely do). Debugging with F5 is discussed in Chapter 18, and you’re advised to use Ctrl+F5 until then. If you see an information bar warning about intranet settings in Internet Explorer, click Turn on Intranet Settings. If you don’t see the date and time in the page, or if you get an error, look again at the code in the welcome message. It starts with an angle bracket (<) followed by a percentage symbol and a colon. It closes with a single percentage sign and another angle bracket (>). Also, make sure you typed in the code exactly as shown here, including capitalization. This is especially true when you are using C#, because that language is case sensitive.


9. Notice how a small icon representing IIS Express has appeared in the tray

bar of Windows, visible in Figure 1-7.


The icon belongs to the built-in web server called IIS Express. This web server has been started by VS automatically to serve the request for your page. You learn more about how the web server processes your page in the later section. If you don’t see the icon in the tray, click the arrow near the other icons in the Windows tray and click the Customize option. Then set IIS Express System Tray to Show Icon and Notifications. That’s it. You just created your very first ASP.NET website with Visual Studio.

How It Works

Although the website you created in this Try It Out is quite simple, the process that eventually results in the page Default.aspx being displayed in your browser isn’t so simple. All by itself, an ASP.NET page (also referred to as an ASPX page because of its extension, or a Web Form) can’t do much. It needs to be processed and served by a web server before your browser can display it. That’s why VS automatically started up IIS Express to handle the request for the page. Next, it started up your default web browser and directed it to the address of the web server (http://localhost:49815/Default in the Try It Out example), although the actual port number in the address may change every time you start the web server because it is randomly chosen by VS. It’s important to realize that the ASPX file you modified in VS is not the same as the one that eventually gets displayed by the browser.

When you create a page in VS, you add markup to it. The markup in an ASPX page is a combination of HTML, code for ASP.NET Server Controls (which you learn more about in this article and in and the future articles, code written in Visual Basic.NET or C#, and more. When you request an ASPX page in your browser, the web server processes the page, executes any server-side code it finds in the file, and effectively transforms the ASP.NET markup into plain HTML
that it then sends to the browser, where it is displayed. In the preceding Try It Out, the resulting HTML causes the browser to display the current date and time. HTML, or HyperText Markup Language, is the language that browsers use to display a web page. You learn how HTML looks and how to use it later article.

NEXT:  Workingwith ASP.NET Server Controls

No comments:

Post a Comment

We are happy for leaving comments,we will don't let you bite stay with us

Popular Posts

Contact Form

Name

Email *

Message *