码迷,mamicode.com
首页 > Web开发 > 详细

ASP.Net初级学习一(基本语句入门)

时间:2014-11-21 23:13:28      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   sp   for   on   

 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>

 

ASP.Net初级学习一(基本语句入门)

标签:style   blog   http   io   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/sytu/p/4113927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!