Handler 页面传值

今天做东西的时候用的东西 ,不太会所以就记一下 以便以后回头复习  嘿嘿 

在aspx页面中获取页面元素的值 在后台可以直接取值  但是这种取值会有一定的刷新   所以就使用的Handler页面处理代码了

页面元素什么的都不写了  写一个方法是那个意思就行了

 里面用了jquery.popup这个外部JQ文件

aspx页面
 
   
1 < script language = " javascript " type = " text/javascript " >
2
3
4 function btnAddSure_onclick() {
5 // 获取值
6 var Name = $( " #<% =txtSystemName.ClientID%> " ).val();
7 var URL = $( " #<%=txtSystemURL.ClientID %> " ).val();
8 var SystemType = $( " #<% =txtSystemType.ClientID%> " ).val()
9 var SytemDscribe = $( " #<%=TextDescribe.ClientID %> " ).val();
10 var form = $( " #form " );
11 // 向Handler页面中传值 Type相当于Key值
12 $.post(
13 " /ashx/AddSystem.ashx?Type=InsertSystem " ,
14 {
15 Name: Name,
16 URL: URL,
17 SystemType: SystemType,
18 SystemDscribe: SytemDscribe
19
20 },
21 // 回调函数 引用外部JS和CS文件
22 function (data) {
23 if (data == " false " ) {
24 alert(data);
25 pop({ text: ' 添加系统失败! ' , title: ' 提示信息 ' }, 0 , function () { });
26 } else {
27 pop({ text: ' 添加系统成功! ' , title: ' 提示信息 ' }, 1 , function () {
28 // 清空元素值
29 $( " input:text " ).each(function () {
30 $( this ).val( "" );
31 }), $( " #TextDescribe " ).val( "" ) ;
32 });
33
34 }
35 }
36 );
37
38
39 }

在Handler页面中代码:

 

ashx页面
 
   
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using UserService.Model;
6 using UserService.BLL;
7
8 namespace UserService.Web.ashx
9 {
10 /// <summary>
11 /// AddSystem 的摘要说明
12 /// </summary>
13 public class AddSystem : IHttpHandler
14 {
15 // 获取Type值
16 public void ProcessRequest(HttpContext context)
17 {
18 context.Response.ContentType = " text/plain " ;
19 string commandType = "" ;
20 if (context.Request.QueryString[ " Type " ] != null )
21 {
22 commandType = context.Request.QueryString[ " Type " ];
23 }
24 else
25 {
26 return ;
27 }
28 if (commandType.Equals( " InsertSystem " ))
29 {
30 InsertSystem(context);
31 }
32
33 }
34 // 实现接口成员
35 public bool IsReusable
36 {
37 get
38 {
39 return false ;
40 }
41 }
42
43 /// <summary>
44 /// 添加系统
45 /// </summary>
46 /// <param name="context"></param>
47 public void InsertSystem(HttpContext context)
48 {
49 SystemInfo sysInfo = GetInfo(context);
50 if (SystemBll.InsertSystem(sysInfo))
51 {
52 context.Response.Write( " true " );
53 }
54 else
55 {
56 context.Response.Write( " false " );
57 }
58
59 }
60
61
62 // 用来接收添加或修改时文本框的值
63 public SystemInfo GetInfo(HttpContext context)
64 {
65 string uniqueID;
66
67 if (context.Request.Form[ " UniqueID " ] != null )
68 {
69 uniqueID = context.Request.Form[ " UniqueID " ];
70 }
71 else
72 {
73 // 生成UniqueID
74 uniqueID = System.Guid.NewGuid().ToString();
75 }
76 // 获取传入的值
77 string Name = context.Request.Form[ " Name " ].ToString();
78 string URL = context.Request.Form[ " URL " ].ToString();
79 string SystemType = context.Request.Form[ " SystemType " ].ToString();
80 string SystemDscribe = context.Request.Form[ " SystemDscribe " ].ToString();
81
82 SystemInfo sysInfo = new SystemInfo(uniqueID, Name, SystemDscribe, URL, SystemType);
83 return sysInfo;
84
85
86 }
87 }
88 }

从这上面看终于知道为什么要好好学JQ和JS还有AJAX了  要是用JQ和AJAX 代码比这个少多了  看着也比这个爽多了 这个项目做了一定把这三个再学一遍   不然以后真的要写东西会好麻烦的

一定要加油哟   嘿嘿

转载于:https://www.cnblogs.com/zyuhong/archive/2010/11/16/1878718.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值