日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

步步为营-72-asp.net简单练习(通过webForm实现一些简单实例)

發布時間:2024/10/12 asp.net 119 豆豆
生活随笔 收集整理的這篇文章主要介紹了 步步为营-72-asp.net简单练习(通过webForm实现一些简单实例) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

WebForm成功之處在于:實現的代碼后置,和asp相比實現了html代碼和C#代碼分離.但 aspx和aspx.cs之間的強耦合和性能方面(特別是服務器控件)做的不是很好.

參照步步為營-68完成相同功能的小例子

1?實現自增

1.1?通過客戶端控件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="01-自增.aspx.cs" Inherits="_01_小實例._01_自增" %><!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> </head> <body><form id="form1" action="" method="post"><input type="text" name="num" value="<%=Num %> "/><input type="submit" value="自增" /></form> </body> </html> aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace _01_小實例 {public partial class _01_自增 : System.Web.UI.Page{public int Num { get; set; }protected void Page_Load(object sender, EventArgs e){if (Request["num"]!= null){int num = int.Parse(Request["num"]);num++;Num = num;}}} } aspx.cs

1.2?通過服務端控件實現

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="01-自增(服務端控件).aspx.cs" Inherits="_01_小實例._01_自增_服務端控件_" %><!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> </head> <body><form id="form1" runat="server"><div><asp:TextBox ID="txtNum" runat="server">0</asp:TextBox><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="自增" /></div></form> </body> </html> aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace _01_小實例 {public partial class _01_自增_服務端控件_ : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){txtNum.Text = (Convert.ToInt32(txtNum.Text) + 1).ToString();}} } aspx.cs

2?實現加法計算器

2.1?通過客戶端控件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="02-加法計算器.aspx.cs" Inherits="_01_小實例._02_加法計算器" %><!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> </head> <body><form id="form1" method="post" action=""><input type="text" name="num1" value="<%=Num1 %>" />+<input type="text" name="num2" value="<%=Num2 %>" /><input type="submit" value="="/><input type="text" name="result" value="<%=Result %>" /></form> </body> </html> aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace _01_小實例 {public partial class _02_加法計算器 : System.Web.UI.Page{public int Num1 { get; set; }public int Num2 { get; set; }public int Result { get; set; }protected void Page_Load(object sender, EventArgs e){if (String.IsNullOrEmpty(Request["num1"]) || String.IsNullOrEmpty(Request["num2"])){return;}int num1 = int.Parse(Request["num1"]);int num2 = int.Parse(Request["num2"]);int result = num1 + num2;Num1 = num1;Num2 = num2;Result = result;}} } aspx.cs

2.2?通過服務端控件實現

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="02-加法計算器(服務端控件).aspx.cs" Inherits="_01_小實例._02_加法計算器_服務端控件_" %><!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> </head> <body><form id="form1" runat="server"><asp:TextBox ID="txtNum1" runat="server">0</asp:TextBox>+<asp:TextBox ID="txtNum2" runat="server">0</asp:TextBox> &nbsp;<asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="=" /><asp:TextBox ID="txtResult" runat="server">0</asp:TextBox></form> </body> </html> aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace _01_小實例 { public partial class _02_加法計算器_服務端控件_ : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnAdd_Click(object sender, EventArgs e) { txtResult.Text = (int.Parse(txtNum1.Text) + int.Parse(txtNum2.Text)).ToString(); } } } aspx.cs

3?div的自增長

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="03-div的增長.aspx.cs" Inherits="_01_小實例._03_div的增長" %><!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> </head> <body><div style="border:solid 1px red; width:<%=Len%>px;height:<%=Len%>px""><form id="form1" method="post" action=""><input type="hidden" name="len" value="<%=Len%>"/><input type="submit" value="" /></form></div></body> </html> aspx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace _01_小實例 {public partial class _03_div的增長 : System.Web.UI.Page{public int Len { get; set; }protected void Page_Load(object sender, EventArgs e){int len ;if (!string.IsNullOrEmpty(Request["len"])){len = Convert.ToInt32(Request["len"]) +10;}else{len = 50;}Len = len;}} } aspx.cs

轉載于:https://www.cnblogs.com/YK2012/p/7017526.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的步步为营-72-asp.net简单练习(通过webForm实现一些简单实例)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。