diff --git "a/10\344\275\231\351\207\221\346\230\237/Webform\345\210\235\350\257\206.md" "b/10\344\275\231\351\207\221\346\230\237/Webform\345\210\235\350\257\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..fa94bba85bed2e9b2e9917c8d4f0560f2cc02c4c --- /dev/null +++ "b/10\344\275\231\351\207\221\346\230\237/Webform\345\210\235\350\257\206.md" @@ -0,0 +1,58 @@ +## Webform初始 + +action = "一般处理程序" +method = post(隐式发送) +method = get(显式发送) + +创建第一个Web应用窗体 + +```asp +
+``` + +```c# +//一般处理程序 +public void ProcessRequest(HttpContext context) +{ + context.Response.ContentType = "text/plain"; + //1.从前台接收数据到后台 + string uname = context.Request.Params["uname"]; + string upwd = context.Request.Params["upwd"]; + DATA.LoginCheck lc = new DATA.LoginCheck(); + if (lc.CheckAccount(uname, upwd)) + { + context.Response.Write("登陆成功"); + } + else + { + context.Response.Write("用户名或者密码错误"); + } +} +public bool IsReusable //是否自动缓存 +{ + get + { + return false; + } +} +``` + +```c# +//模拟数据库 +public bool CheckAccount(string uname, string upwd) +{ + if (uname == "123" && upwd == "admin") + { + return true; + } + else + { + return false; + } +} +``` + diff --git "a/24 \351\231\210\351\222\260\351\224\213/5.20 ASP\345\206\205\347\275\256\345\257\271\350\261\241\347\254\224\350\256\260.md" "b/10\344\275\231\351\207\221\346\230\237/\345\206\205\347\275\256\345\257\271\350\261\241.md" similarity index 69% rename from "24 \351\231\210\351\222\260\351\224\213/5.20 ASP\345\206\205\347\275\256\345\257\271\350\261\241\347\254\224\350\256\260.md" rename to "10\344\275\231\351\207\221\346\230\237/\345\206\205\347\275\256\345\257\271\350\261\241.md" index bb53ad97a1e5120fce2ed136efe23dac273dda4e..ba86914e6333df8826067c2f9e2d74eeb7c22118 100644 --- "a/24 \351\231\210\351\222\260\351\224\213/5.20 ASP\345\206\205\347\275\256\345\257\271\350\261\241\347\254\224\350\256\260.md" +++ "b/10\344\275\231\351\207\221\346\230\237/\345\206\205\347\275\256\345\257\271\350\261\241.md" @@ -1,175 +1,206 @@ -``` -Transfer 方法把一个 ASP 文件中创建的所有状态信息(所有 application/session 变量以及所有 request 集合中的项目)发送(传输)到另一个 ASP 文件中。 - -当第二个 ASP 完成任何时,它不会返回到第一个 ASP 页面。 - -注意:Transfer 方法是 Response.Redirect 的一个高效的替代方案。当 Server.Transfer 方法在服务器上向另外的 ASP 页面传输执行时,重定向强制 Web 服务器处理额外的请求,避免了额外的周折 - -把第一个继承到第二个 -``` - -``` -Execute 方法从另外一个 ASP 文件中执行 ASP 文件。在被调用的 .asp 文件执行完毕后,控制权会返回原始的 .asp 文件。 - -把第二个返回到第一个 -``` - -``` - -Request对象 -Response对象 -Server对象 -ViewState对象 - -protected void Page_Load(object sender, EventArgs e) -{ - //初始化 - if(!IsPostBack) - { - ViewState["lbl1"] = 0; - } -} -//没有成员变量 -//HTTP协议:无状态 -protected void Button1_Click(object sender, EventArgs e) -{ - int c = (int)ViewState["lbl1"]; - c++; - lbl1.Text = c.ToString(); - ViewState["lbl1"] = c; -} -Request对象 - QueryString(查询字符串):获取通过URL传递过来的数据 - Form(表单数据):获取通过表单提交传输的数据 - ServerVariables属性:获取Web服务器变量的集合 - Params:以上三种方式传输的内容都可以使用该属性获取 - -protected void Page_Load(object sender, EventArgs e) -{ - -} - -protected void Page_Load(object sender, EventArgs e) -{ - string name = Request.QueryString["name"]; - string c = Request.QueryString["class"]; - Response.Write($"name:{name}{c}班"); - string name1 = Request.Params["name"]; - string c1 = Request.Params["class"]; - Response.Write($"name:{name1}{c1}班"); -} -Response对象 -Response.Write()方法:向当前HTTP响应流写入文本,使其成为返回页面的一部分 - -Response.Redirect()方法:将用户从请求页面重新定向或转到另一页面 - - -protected void Page_Load(object sender, EventArgs e) -{ - -} -protected void btn_Click(object sender, EventArgs e) -{ - string name = box1.Text; - string sex = ""; - //checked - if (rbtn1.Checked == true) - { - sex = "先生"; - } - else - { - sex = "女士"; - } - Response.Redirect($"Page2.aspx?name={name}&sex={sex}"); -} - -protected void Page_Load(object sender, EventArgs e)= -{ - //Response重定向: - //改变网址: - //外部重定向 - //Response.Redirect("https://www.baidu.com/"); - //内部重定向 - //Response.Redirect("Page3.aspx"); - string name = Request.Params["name"]; - string sex = Request.Params["sex"]; - Response.Write($"欢迎{name}{sex}登录."); -} -protected void btn1_Click(object sender, EventArgs e) -{ - //重定向 Response对象 - Response.Redirect("Page3.aspx"); -} - -protected void Page_Load(object sender, EventArgs e) -{ - -} -Server对象 - Server.Execute()方法:在URL参数指定的页面处理完后,控制权返回给先前的页面或调用此方法的页面,并且从此方法调用后的语句继续执行。 - Server.Transfer()方法:在URL参数指定的页面处理完后,控制权不会返回给先前的页面,也不会返回给调用此方法的页面,直到在新页面完成结束。 - -protected void Page_Load(object sender, EventArgs e)= -{ - -} -protected void btn2_Click(object sender, EventArgs e) -{ - //Server对象 - Server.Execute("Page2.aspx"); - Response.Write("Execute"); -} -protected void btn3_Click(object sender, EventArgs e) -{ - Server.Transfer("Page2.aspx"); - Response.Write("Transfer"); -} - -protected void Page_Load(object sender, EventArgs e) -{ - -} -``` - +#### ViewState对象 + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + //初始化 + if(!IsPostBack) + { + ViewState["lbl1"] = 0; + } +} +//没有成员变量 +//HTTP协议:无状态 +protected void Button1_Click(object sender, EventArgs e) +{ + int c = (int)ViewState["lbl1"]; + c++; + lbl1.Text = c.ToString(); + ViewState["lbl1"] = c; +} +``` + +#### Request对象 + +- [x] QueryString(查询字符串):获取通过URL传递过来的数据 +- [ ] Form(表单数据):获取通过表单提交传输的数据 +- [ ] ServerVariables属性:获取Web服务器变量的集合 +- [x] Params:以上三种方式传输的内容都可以使用该属性获取 + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + +} +``` + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + string name = Request.QueryString["name"]; + string c = Request.QueryString["class"]; + Response.Write($"name:{name}{c}班"); + string name1 = Request.Params["name"]; + string c1 = Request.Params["class"]; + Response.Write($"name:{name1}{c1}班"); +} +``` + +#### Response对象 + +Response.Write()方法:向当前HTTP响应流写入文本,使其成为返回页面的一部分 + +Response.Redirect()方法:将用户从请求页面重新定向或转到另一页面 + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + +} +protected void btn_Click(object sender, EventArgs e) +{ + string name = box1.Text; + string sex = ""; + //checked + if (rbtn1.Checked == true) + { + sex = "先生"; + } + else + { + sex = "女士"; + } + Response.Redirect($"Page2.aspx?name={name}&sex={sex}"); +} +``` + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e)= +{ + //Response重定向: + //改变网址: + //外部重定向 + //Response.Redirect("https://www.baidu.com/"); + //内部重定向 + //Response.Redirect("Page3.aspx"); + string name = Request.Params["name"]; + string sex = Request.Params["sex"]; + Response.Write($"欢迎{name}{sex}登录."); +} +protected void btn1_Click(object sender, EventArgs e) +{ + //重定向 Response对象 + Response.Redirect("Page3.aspx"); +} +``` + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + +} +``` + +#### Server对象 + +- [x] Server.Execute()方法:在URL参数指定的页面处理完后,控制权返回给先前的页面或调用此方法的页面,并且从此方法调用后的语句继续执行。 +- [x] Server.Transfer()方法:在URL参数指定的页面处理完后,控制权不会返回给先前的页面,也不会返回给调用此方法的页面,直到在新页面完成结束。 + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e)= +{ + +} +protected void btn2_Click(object sender, EventArgs e) +{ + //Server对象 + Server.Execute("Page2.aspx"); + Response.Write("Execute"); +} +protected void btn3_Click(object sender, EventArgs e) +{ + Server.Transfer("Page2.aspx"); + Response.Write("Transfer"); +} +``` + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + +} +``` + diff --git "a/10\344\275\231\351\207\221\346\230\237/\351\241\265\351\235\242\345\257\271\350\261\241Page.md" "b/10\344\275\231\351\207\221\346\230\237/\351\241\265\351\235\242\345\257\271\350\261\241Page.md" new file mode 100644 index 0000000000000000000000000000000000000000..34e800569d8421334be84d1e30ec37dcf45ee153 --- /dev/null +++ "b/10\344\275\231\351\207\221\346\230\237/\351\241\265\351\235\242\345\257\271\350\261\241Page.md" @@ -0,0 +1,121 @@ +## 页面对象Page + +#### 网页生成过程分析 + +```tex +第一次请求: + 1.ASp.NET引擎 + 2.后台.cs编码类 + 3.生成的页面类-编译 + 4.数据库-处理 + 5.程序集处理并合成数据(响应) +第二次请求: + 5.程序集处理并合成数据(响应) +``` + +#### 网页生成过程总结 + +```tex +1.客户端点击提交按钮或者触发控件的事件 +2.服务器端刷新整个页面 +3.执行page_load事件 +4.执行具体控件的事件并给页面控制赋值 +5.重新生成新页面的HTML +6.使用Response对象返回包含新数据的html页面 +7.浏览器看到刷新后的页面 +``` + +#### Page.IsPostBack属性 + +```asp + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + //如果是第一次加载: + //TextBox1.Text = "请输入账号"; + //如果是回发, + + //第一次加载 + if (!IsPostBack) + { + TextBox1.Text = "请输入账号"; + } + else //回发 + { + + } +} +protected void Button1_Click(object sender, EventArgs e) +{ + TextBox2.Text = TextBox1.Text; +} +``` + +#### 页面传值 + +```tex +//存放信息 +ViewState["ID名称"]="1"; +//读取信息 +String ID名称 = ViewState["ID名称"].ToString(); +``` + +#### 跨页面传值 + +```asp +页面Page1 + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + +} +``` + +```asp +页面Page2 + +``` + +```c# +protected void Page_Load(object sender, EventArgs e) +{ + //判断是否起始页,如果是起始页,Page.PreviousPage将为空 + if (Page.PreviousPage != null) + { + //PreviousPage.FindControl(string id):在当前的命名容器中(这里指定的是PreviousPage)搜索 指定 id + TextBox t1 = (TextBox)PreviousPage.FindControl("TextBox1"); + TextBox t2 = (TextBox)PreviousPage.FindControl("TextBox2"); + if(t1.Text == "123" && t2.Text == "admin") + { + lbl2.Text = "登陆成功"; + } + else + { + lbl2.Text = "用户名或密码错误"; + } + } +} +``` + diff --git "a/12 \345\221\250\346\263\275\345\274\272/\347\254\224\350\256\260.md" "b/12 \345\221\250\346\263\275\345\274\272/\347\254\224\350\256\260.md" deleted file mode 100644 index 4d7d034c1d173709650f554ce269cab64e26f851..0000000000000000000000000000000000000000 --- "a/12 \345\221\250\346\263\275\345\274\272/\347\254\224\350\256\260.md" +++ /dev/null @@ -1,47 +0,0 @@ -̬ҳ: - .html .htm βҳ - ֻܵʾıͼ - ûӻûʾͬҳ -˿: - ʾıͼ - Ըû̬ʾͬҳ(̨) - -C/SClient/ServerдͨøܵPCվСͻ -ôݿ⣨MySQL֪ʶ⡱)ϵͳOracleSybaseInFORMix -SQL ServerͻҪװרõĿͻ - -B/Browser/ServerдͻֻҪװһBrowser -Netscape NavigatorInternet ExplorerװOracleSybaseInFORMix - SQL Serverݿ⡣ֽṹ£ûȫͨWWWʵ֣ -һǰʵ֣Ҫڷʵ֡ -ͨeb Server ͬݿݽ - -ǰ̨ݵ̨ -string uname = context.Request.Params["uname"] -DATA.LoginCheck lc = new DATA.LoginCheck(); - -public bool IsReusable //ǷԶ - -Page.PreviousPage != null - -Page.IsPostBack ȷҳ״γֻӦط - -TextBox tname= (TextBox)PreviousPage.FindControl("TextBox1") - ؼֵ ؼ -ȡϢ -String NameID = ViewState["nameID"].ToString(); - -PostBackUrl= ת - -ASP.NET Web ԭ -{ UserLogin.aspx ӻ -UserLogin.aspx.cs () } --->.aspxaspx.csͬ - Webformվҳ Webform - - - - - - - diff --git "a/\346\261\237\345\230\211\345\205\264/Asp.net\347\254\224\350\256\260.md" "b/\346\261\237\345\230\211\345\205\264/Asp.net\347\254\224\350\256\260.md" deleted file mode 100644 index c2c10eca24e4b2d86f6378773d1fe04dc1712dce..0000000000000000000000000000000000000000 --- "a/\346\261\237\345\230\211\345\205\264/Asp.net\347\254\224\350\256\260.md" +++ /dev/null @@ -1,552 +0,0 @@ -# Asp.net笔记 - -## 初识 - -### cs - -C/S是Client/Server的缩写。服务器通常采用高性能的PC、工作站或小型机, - -并采用大型数据库(“MySQL知识库”)系统,如Oracle、Sybase、InFORMix或 - -SQL Server。客户端需要安装专用的客户端软件。 - -### bs - -B/S是Browser/Server的缩写,客户机上只要安装一个浏览器(Browser), - -如Netscape Navigator或Internet Explorer,服务器安装Oracle、Sybase、InFORMix或 - - SQL Server等数据库。在这种结构下,用户界面完全通过WWW浏览器实现, - -一部分事务逻辑在前端实现,但是主要事务逻辑在服务器端实现。 - -浏览器通过Web Server 同数据库进行数据交互。 - -## 静态网页&服务器端开发技术 - -静态网页: - - 以.html 或者.htm 结尾的网页 - - 只能单纯的显示文本和图像 - - 无法和用户接互,无法根据用户的请求显示不同的网页内容 - -服务器端开发技术: - - 不仅可以显示文本和图像 - - 还可以根据用户请求,动态显示不同的网页内容(与后台交互) - -例子 - -html页面 - - - - - -