1.<%@Page%>中的Codebehind、AutoEventWireup、Inherits有何作用?

AutoEventWireup --- 指示是否自动启用页事件。 Codebehind --- 指示后台代码文件。 Inherits --- 继承类。

AutoEventWireup:指示该页的事件是否为自动连网的。如果启用事件自动连网,则为 true;否则,为 false。 Inherits:定义供页继承的代码隐藏类。可以是从 Page 类派生的任何类。 Codebehind:代码绑定文件的名称。

Page language="c#" :指定为c#语言;
Codebehind 属性并不是一个真正的 ASP.NET 属性,在ASP.NET 文档中是找不到它的。
它其实只是一个 Visual Studio .NET 属性,
Visual Studio .NET 就是借用这个属性来很好地跟踪管理项目中的 Web 窗体和与之相对的代码隐藏文件,
比如当你在设计环境中往 Web 窗体上放入一个服务器控件时,
Visual Studio .NET 将自动找到与该 Web 窗体相对应的代码隐藏文件,并自动插入相关的代码。

AutoEventWireup:是否自动绑定页面处理事件,false表示不自动绑定;

Inherits 属性用于定义当前 Web 窗体所继承的代码隐藏类(该类是 System.Web.UI.Page 的派生类)。
这个 inherits 属性只用于采用代码隐藏方式编写的 Web 窗体,也就是,如果你的代码全都是在 Web 窗体的
<script runat="server"></script> 标签中,就不必用这个属性了。

Codebehind="PreDeliver.aspx.cs" 表示该页的后置代码在当前目录下的PreDeliver.aspx.cs文件中; AutoEventWireup="false" 表示是否自动地将页面的事件和相应的方法绑定到一起,一般这个什要设为false,因为若设为true有可能两次调用相同的事件代码。 Inherits="Issue.Pre"表示页面中的控件是在哪个类中定义的。

基础知识:AutoEventWireup属性   AutoEventWireup属性决定事件句柄怎样连接到控件事件中。当AutoEventWireup设置为true时,ASP.NET决定调用类中的哪一种方法来响应那些在用户与网页的交互中产生的事件。ASP.NET将不必用代理就可以为一个Web控件调用合适的事件句柄,对程序员而言,这样可以无需为事件句柄添加代理。在程序员不是使用Visual Studio因而必须自己添加代码的情况下,这是非常方便的。   当Visual Studio生成一个ASPX文件时,因为Visual Studio为我们生成必要的时间代理,所以将AutoEventWireup设为false。   如果在Visual Studio中将AutoEventWireup设为true,那么一个事件句柄将会被调用两次,一次通过代理,一次是AutoEventWireup的结果。   runat属性,设置为“Server”,说明由服务器来处理表单并生成发送给客户的HTML代码。   同一类型的Web控件可以映射到不同的HTML元素,这取决于客户端的浏览器和Web空间的参数设置。   Page类定义了所请求的网页,位于System.Web.UI名字空间,它包含了为创建基于Web的应用和控件所需的类。   类Page也提供了创建基于Web的应用所需的事件句柄和必要对象。   除了Page类,System.Web.UI还包括Control类。这是一个为所有的Web控件提供一般功能的基类。      ASPX文件和代码后置文件是怎样被用于创建那些发送给客户的网页的呢?首先,类WebTimeTest继承了定义了网页一般功能的Page类。除了继承这些功能以外,WebTimeTest还定义了一些自己特有的功能。   代码后置文件就是定义了这一功能的文件,而ASPX文件定义了GUI。当客户请求一个ASPX文件时,在包含网页的可视化部分(在ASPX文件中定义)和包含网页的逻辑部分(在代码后置文件中定义)的现场后面创建一个类。新类继承自Page。   当网页首次被请求时,这个类被编译并且创建一个实例。这个实例表示网页,它创建了被传送给客户的HTML。由编译过的类创建的组件被放置在项目的Bin目录中。      一旦一个网页实例已经创建,多个用户就可以使用这一实例来访问这个网页——不再需要重新编译。项目仅仅在程序员修改应用程序后才需要重新编译,这些变化由运行时间环境检测,并且项目将被重新编译来反应变化的内。

转载于:https://www.cnblogs.com/xingxing00/p/3731416.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
eBook Visual C#2010 Step by Step 教學pdf and 範例程式 Microsoft Visual C# is a powerful but simple language aimed primarily at developers creating applications by using the Microsoft .NET Framework. It inherits many of the best features of C++ and Microsoft Visual Basic, but few of the inconsistencies and anachronisms, resulting in a cleaner and more logical language. C# 1.0 made its public debut in 2001. The advent of C# 2.0 with Visual Studio 2005 saw several important new features added to the language, including Generics, Iterators, and anonymous methods. C# 3.0 which was released with Visual Studio 2008, added extension methods, lambda expressions, and most famously of all, the Language Integrated Query facility, or LINQ. The latest incarnation of the language, C# 4.0, provides further enhancements that improve its interoperability with other languages and technologies. These features include support for named and optional arguments, the dynamic type which indicates that the language runtime should implement late binding for an object, and variance which resolves some issues in the way in which generic interfaces are defined. C# 4.0 takes advantage of the latest version of the .NET Framework, also version 4.0. There are many additions to the .NET Framework in this release, but arguably the most significant are the classes and types that constitute the Task Parallel Library (TPL). Using the TPL, you can now build highly scalable applications that can take full advantage of multi-core processors quickly and easily. The support for Web services and Windows Communication Foundation (WCF) has also been extended; you can now build services that follow the REST model as well as the more traditional SOAP scheme. The development environment provided by Microsoft Visual Studio 2010 makes all these powerful features easy to use, and the many new wizards and enhancements included in Visual Studio 2010 can greatly improve your productivity as a developer.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Hotel.WebForm1" EnableEventValidation="false" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <link rel="stylesheet" href="Assets/Libraries/Bootstrap/css/bootstrap.min.css" /> <style> body{ background-image:url(../Assets/Images/hotel4.jpg); background-size:cover; } .container-fluid{ opacity:0.9; } </style> </head> <body> <form id="form1" runat="server" > <div> <div class="container-fluid"> <div class="row" style="height:200px"></div> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4 bg-light rounded-3"> <h1 class="text-text-success text-center">皇家理工度假酒店</h1> <form> <div class="mb-3"> <label for="UserTb" class="form-label">用户名</label> <input type="text" class="form-control" id="UserTb" runat="server" required="required"> </div> <div class="mb-3"> <label for="PasswordTb" class="form-label">密码</label> <input type="password" class="form-control" id="PasswordTb" runat="server" required="required"> </div> <div class="mb-3"> <label id="ErrMsg" class="text-danger" runat="server"></label> <input type="radio" id="AdminCb" runat="server" name="Role"><label class="text-success">管理员</label> <input type="radio" id="UserCb" runat="server" name="Role"><label class="text-success">用户</label> </div> <div class="d-grid"> <asp:Button ID="LoginBtn" runat="server" Text="登陆" class="btn btn-success btn-block" OnClick="LoginBtn_Click" /> </div> <br /> </form> </div> <div class="col-md-4"></div> </div> </div> </div> </form> </body> </html>我在form添加了align=center属性但是删除后却依旧运行了原先配置
最新发布
05-27

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值