转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
Web Sites Created Using ASP.NET         ★★★★

Web Sites Created Using ASP.NET

作者:闵涛 文章来源:闵涛的学习笔记 点击数:849 更新时间:2009/4/23 10:39:17
Web Sites Created Using ASP.NET
ASP seemed great a few years ago, but now ASP.NET provides a simpler,
faster, more powerful way to create Web applications. Instead of using a
scripting language, you may now create real, fully compiled applications.
You can write these applications using any of the .NET-compliant languages
available, and you can use the great tools provided by Visual Studio .NET
to do your work. Any developer can now create full-featured, powerful Web
applications.

Creating a New ASP.NET Application
Enough talking about it梙ow about actually creating a simple Web
application? To get started, you''''ll create a project with a Web Form that
allows users to input first and last names. After entering the data into
these two text controls on the Web page, a user clicks a button and sees
the entered information appear in a label below the button.

Figure 5.1 shows the sample Web Form you will create.

Figure 5.1. This simple page allows you to enter values, and clicking the
button runs code to process those values.


Creating the Login Form
To get started, you''''ll need to create a new Web Application project in
Visual Studio .NET:

Start Visual Studio .NET and select the File, New, Project menu item.

In the New Project dialog box, select Visual Basic Projects in the Project
Types pane.

In the Templates pane, select ASP.NET Web Application.

In the Location text box, enter http://www.localhost/Jumpstart/Northwind as
the location for the project.

Click OK to allow Visual Studio .NET to create the virtual root, add the
project template, and prepare for you to begin working on the project. This
may take a few moments.

By default, Visual Studio .NET creates a page named WebForm1.aspx. Although
you could develop your application using this page, you''''ll generally want
to rename the page, the code file, and the programming class contained
within the code file. It''''s easier to simply delete the whole page and
create a new one, using your own name.

Select WebForm1.aspx in the Solution Explorer window (most likely, the
Solution Explorer window will appear in the upper-right corner of the
Visual Studio .NET environment), right-click, and select Delete from the
context menu.

Select the Project, Add Web Form menu item.

Set the name of this new page to Login.aspx and then click Open to add the
page.

Use the View, Toolbox menu item to ensure that the Toolbox window is
visible. Then add controls and set properties as shown here.

Control Type  Property  Value 
Label  ID  Label1 
  Text  First Name 
TextBox  ID  txtFirst 
Label  ID  Label2 
  Text  Last Name 
TextBox  ID  txtLast 
Button  ID  btnLogin 
  Text  Login 
Label  ID  lblName 
  BorderStyle  Inset 
  Text  (Delete the text, so you see just the label''''s name.) 


To view the layout information you''''ve created, choose the View, HTML Source
menu item (or click the HTML tab at the bottom of the designer window).
You''''ll see HTML but no programming code梩hat goes into a separate location.

Select the View, Design menu item to get back to the normal design view.

Select File, Save All to save your project.



Running the Login Form
At this point, you can run this application and see the Web Form appear in
your browser. Although this page does not have any functionality yet, this
exercise is a good test to make sure everything is running up to this
point. Here are the steps to follow:

Select Login.aspx in the Solution Explorer window.

Right-click and select Set as Start Page from the context menu.

Press F5 to run this sample application.

TIP

If you have trouble running the application, refer back to the instructions
in Chapter 1, "Getting Started with the Sample Application." You may need
to configure your project to allow debugging.



You should now see the Web Form displayed in your browser, and you can
enter data into the two text fields. If you click the button, nothing will
happen because you have not told it to do anything yet. You need to add
some code in order for the button to have any effect.

TIP

While your page is open in the browser window, right-click and select View
Source from the context menu. Although there will be a bunch of stuff in
the page that you didn''''t put there (ASP.NET adds some useful support that
you''''ll learn about later), you should see standard HTML for the controls
you did place on the page.



Adding Code to the Button
If you want the button to actually "do" anything, you need to add some
code. For this example, you need to add code so that the button posts the
data you entered in the text boxes and fills in the appropriate data in the
label below the button control. Follow these steps to add the Visual Basic
.NET code you need:

Stop the program from running by closing down the browser.

While the page is open in the Visual Studio .NET page designer,
double-click the LogIn button. You will now see a code window appear with
the procedure btnLogin_Click already created for you.

Modify this procedure, which will run when a user clicks the button, so
that it looks like this:

Private Sub btnLogin_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnLogin.Click

  lblName.Text = txtLast.Text & ", " & txtFirst.Text
End Sub

NOTE

In your editor, the code will look slightly different. The first long line
of code, the procedure definition, will appear all on a single line. To
make the code fit on the printed page, we''''ve wrapped this one logical line
of code into multiple physical lines, ending each line with Visual Basic
.NET''''s line continuation characters (a space followed by an underscore).
You needn''''t make this same change in your own code, unless you want to. We
do this throughout this book to make the code visible within the limited
range of printed space.



The code you just wrote retrieved the Text property from both the txtLast
and txtFirst text boxes, and it places the data into the Label control on
the page. If you''''ve ever programmed in any flavor of Visual Basic, this
should look awfully familiar. In fact, the whole point of programming in
.NET is that you should be able to use familiar techniques, like these, no
matter what type of application you''''re creating.

Finally, it''''s time to test your masterpiece.

Run the application by pressing F5 again.

Enter a first and last name and click Login.

If you have done everything correctly, you should see the entered name
appear in the label below the button.

Where did you put your code? When you created the Web Form, you created a
file with an .aspx extension (Login.aspx). This file contains only layout
information, generally. When you added code, you modified a corresponding
file, the "code-behind" file (believe us, we don''''t make these things up),
named Login.aspx.vb. All the programming code goes into this separate file,
as part of a class named Login:

Public Class Login
...

  Private Sub btnLogin_Click( _
   ByVal sender As Object, _


   ByVal e As System.EventArgs) _
   Handles btnLogin.Click

    lblName.Text = txtLast.Text & ", " & txtFirst.Text
  End Sub
End Class

This class defines the programmatic behavior for this page. When you press
F5 to run the project, Visual Studio .NET compiles your class into a DLL.
When you browse to the page, ASP.NET loads the layout information from the
ASPX page as well as the code from the compiled DLL. This separation
provides for all sorts of exciting flexibility (you can update the code on
your site, even while users are currently viewing pages on the site, for
example) and makes it simpler to create sites.

It''''s important to consider what happens when you click the button on the
sample page:

The form posts its data back to the server.

The server recomposes the page using the data you typed in and places it
back into the page. The server then sends the page back to the browser.

The browser renders the page again.

It''''s interesting (and important) to note that if you were using ASP (rather
than ASP.NET), it would be up to you to place the values back into the
appropriate HTML tags. In this case, even after you click the button, the
first name and last name values you entered still appear in the text box
controls. If you were using a standard ASP page, that wouldn''''t be the case.


[聊天工具]Gmail推出新功能:Web Clip__天极Yesky  [聊天工具]Web MSN你玩了吗__天极Yesky
[系统软件]Web Browser Express 概述  [系统软件]对Internet Explorer Web 控件做一点修改
[系统软件]Using dllimport and dllexport in C++ Classes  [常用软件]小技巧:三步实现Web迅雷录制PPLive节目
[常用软件]天网防火墙:打开WEB和FTP服务  [VB.NET程序]使用VB.Net做一个配置web.config功能的WinForm(原…
[VB.NET程序]vb.net控件、web service简述  [VB.NET程序]使用vbscript脚本调用web服务
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台