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

在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 代码比这个少多了  看着也比这个爽多了 这个项目做了一定把这三个再学一遍   不然以后真的要写东西会好麻烦的

一定要加油哟   嘿嘿

posted on 2010-11-16 17:00  雨宏  阅读(570)  评论(0编辑  收藏  举报