From 32aed594d2401b1bd3ffc63e26578610c08e877a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E9=87=91=E6=98=9F?= <3441777097@qq.com> Date: Wed, 18 May 2022 19:12:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Webform\345\210\235\350\257\206.md" | 58 +++++++++ ...51\235\242\345\257\271\350\261\241Page.md" | 121 ++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 "10\344\275\231\351\207\221\346\230\237/Webform\345\210\235\350\257\206.md" create mode 100644 "10\344\275\231\351\207\221\346\230\237/\351\241\265\351\235\242\345\257\271\350\261\241Page.md" 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 0000000..fa94bba --- /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/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 0000000..34e8005 --- /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 = "用户名或密码错误"; + } + } +} +``` + -- Gitee