• 【holm】ASP.NET期末复习指南


    部分章节重点

    ch1 ch2 ASP.NET基础

    .NET运行环境

    .NET Framework 环境结构图

    • .NET框架
      • .NET框架类库
      • CLR

    参考:通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core?

    ASP.NET网页语法

    ASP.NET 应用程序默认文件夹

    • Bin
    • APP_Code
    • App_GlobalResources
    • App_LocalResources
    • App_WebReferences
    • App_Browsers
    • 主题

    ASP.NET网页扩展名

    • .ascx Web用户控件
    • htm HTML页
    • xml XML页
    • .master 母版页
    • .asmx Web服务
    • .asax 全局应用程序类
    • .config Web配置文件
    • .sitemap 网站地图
    • skin 外观文件
    • css 样式表

    页面指令

    • <%@Page%>
    • <%@Import Namespace="Value"%> 一个指令只能导入一个命名空间
    • <%@OutputCache%> 设置用户控件的输出缓存策略
    • <%@Implements Interface="接口名称"%>
    • <%@Register%> 用于创建标记前缀和自定义控件之间的关联关系

    注释

    • <%-- --%> 使用此注释不会输出到浏览器端
    • <!-- -->

    服务器端文件包含

    • <!--#include file|virtual="filename" --> 将指定文件的内容插入 ASP.NET 文件中,包括网页(.aspx 文件)、用户控件文件(.ascx 文件)和 Global.asax 文件。
      • file 相对文件目录的物理路径
      • virtual 相对网站虚拟目录的虚拟路径 (推荐使用)

    ch4 ch5 ASP.NET控件

    ASP.NET页面事件处理

    • 页面事件
      • PreInit事件
      • Init事件
      • Load事件
      • 控件事件
    • IsPostBack属性:如果是为响应客户端回发而加载该页,则为True;否则为False。

    常用的服务器控件

    • 文本控件
      • Label
      • TextBox
      • Literal
    • 按钮
      • Button
      • ImageButton
    • 超链接
      • HyperLink
      • LinkButton 具有超链接外观的命令按钮
    • 选择
      • RadioButtion
      • RadioButtionList
      • CheckBox
      • CheckBoxList
      • ListBox
      • DropDownList
    • 图像
      • Image
    • 容器
      • Panel
      • PalceHoder
    • 文件上传
      • FileUpload
    • 导航
      • TreeView
      • Menu
      • SiteMapPath
    • 数据绑定控件
      • GridView
      • DataList
      • ListView
      • Repeater
      • DetailsView
      • FormView
    • 数据源控件
      • SqlDataSource
      • ObjectDataSource
    • 数据验证
      • RequiredFileValidator
      • CompareValidator
      • RangeValidatore
      • RegularExpressionValidator
      • CustomValidator
      • ValidationSummary

    状态管理

    • 服务器
      • ViewState 对于没有必要维持状态的页面和控件设置EnableViewState=false来禁用ViewState
      • HiddenField
    • 客户端
      • Session
      • Application

    ADO.NET连接SqlServer

    构建ConnectionString

    • 通过程序内代码构建
    //通过SqlServer身份验证 (安全连接)
    string connStr1="Data Source=local;Initial Catalog=DataBaseName;User Id=xx;Password=xx";
    //通过Windows身份验证 (可信连接)
    string connStr2="Data Source=local;Initial Catalog=DataBaseName;IntegratedSecurity=SSPI";
    
    //   Data Source 可简写成 server
    //   Initial Catalog 可简写成 database
    //   User Id 可简写成 uid
    //   PassWord 可简写成 pwd
    
    
    //使用SqlConnectionStringBuilder
    SqlConnectionStringBuilder connStr3 = new SqlConnectionStringBuilder();
    connStr3.DataSource =".";//"local"
    stringBuilder.InitialCatalog = "DabaBaseName";
    stringBuilder.IntegratedSecurity = true;
    
    • 配置到config文件中
      • connectionStrings节点(推荐)
        <connectionStrings>
            <add name="connStr" connectionString="Data Source=local;Initial Catalog=DataBaseName;User Id=xx;Password=xx" providerName="System.Data.SqlClient" />
        </connectionStrings>
    
    • appSettings节点
        <appSettings>
            <add key="connStr" value="Data Source=local;Initial Catalog=DataBaseName;User Id=xx;Password=xx"/>
        </appSettings>
    
    • 读取:string connStr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;

    内置对象

    数据库

    • Connection
    • Command
    • DataReade
    • DataAdapter
    • DataSet
    • DataTable

    网络

    • Server
    • Request
    • Response
    • Session
    • Application
    • Cookie

    数据绑定控件

    • GridView
    • DataList
    • ListView (具有GridView控件编辑数据的功能,同时又具有DataList控件灵活布局的功能)

    AJAX

    ASP.NET AJAX的优点

    • 不会因为PostBack造成整页重新加载造成闪动
    • 异步取回服务器端的数据
    • 跨浏览器的兼容性支持
    • 提供大量内建的客户端控件
    • 可通过web.config配置启用AJAX相关设置

    ASP.NET AJAX架构

    AJAX是Asynchronous JavaScript and XML(中文译做:异步JavaScript和XML技术)的缩写,它是由JavaScript脚本语言、CSS样式表、XMLHttpRequest数据交换对象和DOM文档对象(或XMLDOM文档对象)等多种技术组成的。

    服务器端架构

    • ASP.NET AJAX 服务器端控件
    • ASP.NET AJAX 服务器端扩展控件
    • ASP.NET AJAX 服务器端远端Web Service
    • ASP.NET AJAX 程序的客户端代理

    服务器端控件在运行时会自动生成ASP.NET AJAX 客户端组件,并发送给客户端浏览器执行。

    客户端架构

    • 程序接口
    • API函数
    • 基础类库
    • 封装的XMLHttpRequest对象
    • ASP.NET AJAX XML引擎
    • ASP.NET AJAX 客户端控件

    客户端控件主要在浏览器上运行,主要提供管理界面元素、调用服务器端方法获取数据等功能。

    ASP.NET AJAX 服务器端控件

    负责管理Page页面中国所有的AJAX服务器控件。

    ScriptManager 控件

    管理Page页面中所有的AJAX服务器控件,是AJAX的核心。
    常用属性:

    • EnablePageMethods
    • EnablePartialRendering
    • EnableScriptComponents
    • Script
    • Service
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                    <Scripts>
                        <asp:ScriptReference Path="~/Scripts/validateName.js" />
                    </Scripts>
                    <Services>
                        <asp:ServiceReference Path="~/RandomService.asmx" />
                    </Services>
                </asp:ScriptManager>
    

    ScriptReference类常用属性

    • Assembly
    • Path
    • Name
    • NotifyScriptLoaded

    UpdatePanel 控件

    将ASP.NE服务器控件拖放到UpdatePanel控件中,使原本不具备AJAX能力的控件具有AJAX异步功能。
    常用属性:

    • ContentTemplate (通过<ContentTemplate>元素声明)
    • Triggers (通过<Triggers>元素声明)
      • AsyncPostBackTrigger 用于引发局部更新
      • PostBackTrigger 用于引发整页更新
    • UpdateMode (用于UpdatePanel嵌套)
      • Always 每次Postback后Update会被连带更新
      • Conditional
    • RenderModeRenderMode的属性为Block,则以<DIV>标签来定义程序段;若为Inline,则以<Span>标签来定义程序段。(默认为Block
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    rand num:
                    <br />
                    <div style="text-align: center;  123px; height: 60px; line-height: 60px; background-color: rebeccapurple">
                        <asp:Label ID="Label1" runat="server" Font-Bold="true" Font-Size="18px" />
                    </div>
                    <asp:Button ID="Button1" runat="server" Text="rand num" OnClick="Button1_Click" />
                </ContentTemplate>
                <!-- 控制UpdatePanel外部的控件局部更新 -->
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
            <asp:Button ID="Button2" runat="server" Text="rand num" OnClick="Button1_Click" />
    

    Timer 控件

    注意:使用Timer控件可能会加大Web应用程序的负载。在引入自动回发特性前并在确实需要的时候才推荐使用Timer控件,同时尽可能设置更长的间隔时间。

    • Interval属性
    • Enable属性
    • Tick事件
    <!--AJAXdemo.aspx-->
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000">
                    </asp:Timer>
                    <asp:Label ID="TimeNow" runat="server" />
                </ContentTemplate>
            </asp:UpdatePanel>
    
    //AJAXdemo.aspx.cs (一部分)
            protected void Timer1_Tick(object sender, EventArgs e)
            {
                TimeNow.Text = DateTime.Now.ToString();
            }
    
    • AJAX Control Toolkit 扩展工具包
      • PasswordStrength控件
      • TextBoxWatermark控件
      • SlideShow控件

    参考资料

  • 相关阅读:
    分割线
    PTA 乙级 1053 住房空置率 (20分) C/C++
    5.12 记录
    单词统计
    eclipse导入项目jdk版本不一样
    5.6日 项目回顾
    5.5 记录
    5.3 记录
    5.2 记录
    5.1 记录
  • 原文地址:https://www.cnblogs.com/holm/p/13089900.html
Copyright © 2020-2023  润新知