ASP.Net初级学习一(基本语句入门)
1 <body > 2 <form method="post" action="program.ashx"> 3 <input type="hidden"value="true"name="ispostback" /> 4 <!--隐藏字段的作用是判断是否是提交表单进入program.ashx--> 5 姓名:<input type="text" name="ming"value="@value"/> 6 <input type="submit" value="提交" /> 7 @msg 8 </form> 9 </body> 10 </html> 11 12 13 public void ProcessRequest(HttpContext context) 14 { 15 context.Response.ContentType = "text/html"; 16 string fullpath = context.Server.MapPath("HtmlGetElementByid.html"); 17 string content = File.ReadAllText(fullpath); 18 string msg = ""; 19 string ispostback=context.Request["ispostback"]; 20 string ming = context.Request["ming"]; 21 22 if (ispostback=="true") 23 { 24 context.Response.Write("提交进入"); 25 msg = ming + "你好"; 26 } 27 else 28 { 29 context.Response.Write("直接进入"); 30 } 31 content = content.Replace("@value",ming); 32 content = content.Replace("@msg",msg); 33 context.Response.Write(content); 34 context.Response.Write(ming); 35 }
实现按键值自增
public class IncreaseValue : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string ispostback=context.Request["ispostback"]; string number = context.Request["number"]; if(ispostback=="true") { if (number == "@value") number = "0"; int i = Convert.ToInt32(number); i++; number = i.ToString(); } else { number = "0"; } string path = context.Server.MapPath("IncreaseValue.html"); string content = System.IO.File.ReadAllText(path); content=content.Replace("@value",number); context.Response.Write(content); } <body> <form action="IncreaseValue.ashx"> <input type="hidden"value="true"name="ispostback" /> <input type="text"value="@value"name="number"/> <input type="submit"value="自增" /> </form> </body>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。