初次使用Ajax.net,总结下心得并记录下来

在网上下载Ajax.dll组件,通过引用添加至项目中;

Ajax.dll文件下载: /Files/ProgrammerSystem/Ajax.dll.zip(基于VS2003.net、VS2005.net)

在Web.config中配置节点,如下:
< httpHandlers >
        
< add  verb ="*"  path ="*.ashx"  type ="AjaxPro.AjaxHandlerFactory,AjaxPro" ></ add >
    
</ httpHandlers >

在MeetEdit.aspx.cs文件Page_Load中添加,摘抄部分代码:
         private   void  Page_Load( object  sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            if(Session["emp_id"== null)
            
{
                Response.Redirect(
"../../security/login.aspx");
            }


            AjaxPro.Utility.RegisterTypeForAjax(
typeof(MeetEdit));
        }


        [AjaxPro.AjaxMethod]
        
public   string  [] Save( string  meetTitle, string  meetDate, string  remarkPeople, string  startToOver, string  people, string  data)
        
{
            
if(meetTitle != "" && meetDate != "" && remarkPeople != "" && startToOver != "" && people != "")
            
{
                
if(data != "" && data != null)
                
{
                    
string sql = "update [Meet] Set ";
                    sql 
+= " meetTitle = '"+meetTitle+"', ";
                    sql 
+= " meetDate = '"+meetDate+"',  ";
                    sql 
+= " remarkPeople = '"+remarkPeople+"', ";
                    sql 
+= " startToOver = '"+startToOver+"', ";
                    sql 
+= " people = '"+people+"";
                    sql 
+= " where meetID = '"+ int.Parse(data) +"";

                    DBControl.ExecuteNonQuery(sql);

                    
string [] result = {"<font color='red'>更新成功!</font>",data};
                    
return result;
                }

                
else
                
{
                    
string sql = "insert into [Meet] ";
                    sql 
+= " (meetTitle,meetDate,remarkPeople,startToOver,people,addDate) ";
                    sql 
+= " values ";
                    sql 
+= " ('"+ meetTitle +"','"+meetDate+"','"+remarkPeople+"','"+startToOver+"','"+people+"','"+DateTime.Now.ToString()+"') ";

                    DBControl.ExecuteNonQuery(sql);

                    
string sqlTop = "select top 1 * from [Meet] order by meetID desc";
                    
object o = DBControl.ExecuteScalar(sqlTop);

                    
string [] result = {"<font color='red'>保存成功!</font>",o.ToString()};
                    
return result;
                }

            }

            
else
            
{
                
string [] result = {"<font color='red'>请填写完整!</font>",""};
                
return result;
            }

        }

MeetEdit.aspx页面部分代码如下:
< form  id ="Form1"  method ="post"  runat ="server" >
            
< script >             
                
function SaveData()
                
{
                    
var meetTitle = document.getElementById("tbMeetTitle").value;
                    
var meetDate = document.getElementById("tbMeetDate").value;
                    
var remarkPeople = document.getElementById("tbRemarkPeople").value;
                    
var startToOver = document.getElementById("tbStartToOver").value;
                    
var people = document.getElementById("tbToWho").value;
                    
var data = document.getElementById("iptData").value;
                    
                    OfficeSystem.PersonalWork.OperatingPrinciple.MeetEdit.Save(meetTitle,meetDate,remarkPeople,startToOver,people,data,Save_CallBack);
                }

                
function Save_CallBack(response)
                
{
                    
if(response.error != null)
                    
{
                        alert(response.error);
                        
return;
                    }

                    
else
                    
{
                        
var value = response.value;
                                                
                        document.getElementById(
"lbMsg").innerHTML = value[0];
                        document.getElementById(
"iptData").innerText = value[1];
                        document.getElementById(
"redirect").style.display = "";
                    }

                }

                
function Redirect()
                
{
                    
var data = document.getElementById("iptData").value;
                    location.assign(
"MeetContent.aspx?meetID="+data);
                }

            
</ script >
            
< table  id ="Table1"  cellSpacing ="0"  cellPadding ="0"  width ="800"  border ="0" >
                
< tr >
                    
< td  colSpan ="2" >
                        
< TABLE  id ="Table2"  cellSpacing ="0"  cellPadding ="0"  width ="100%"  border ="0" >
                            
< TBODY >
                                
< TR >
                                    
< td  width ="20"  background ="../../WebPic/main_guide_bg2.gif" > &nbsp; </ td >
                                    
< TD  width ="65%"  background ="../../WebPic/main_guide_bg2.gif" >< IMG  height ="24"  src ="../../WebPic/guide.gif"  width ="18"  align ="absMiddle" > &nbsp; 业务文档 &gt;&gt; 编辑会议纪要 </ TD >
                                    
< TD  class ="guide"  align ="right"  width ="35%"  background ="../../WebPic/main_guide_bg2.gif" >< IMG  src ="../../WebPic/main_r.gif" ></ TD >
                                
</ TR >
                            
</ TBODY >
                        
</ TABLE >
                    
</ td >
                
</ tr >
                
< tr >
                    
< td  colSpan ="2" > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; < label  id ="lbMsg" ></ label >< input  type ="hidden"  id ="iptData"  name ="iptData"  style ="WIDTH:50px" ></ td >
                
</ tr >
                
< tr >
                    
< td  colSpan ="2" >
                        
< table  class ="maintable"  cellSpacing ="1"  cellPadding ="1"  width ="100%"  align ="right" >
                            
< tr >
                                
< td  bgColor ="#84aeff"  colSpan ="2" > &nbsp; </ td >
                            
</ tr >
                            
< tr >
                                
< td  class ="deep"  width ="13%" >
                                    
< div  align ="center" > 例会标题 </ div >
                                
</ td >
                                
< td  width ="45%" >< asp:textbox  id ="tbMeetTitle"  runat ="server"  Columns ="40"  Height ="23px" ></ asp:textbox ></ td >
                            
</ tr >
                            
< tr >
                                
< td  class ="deep"  width ="13%" >
                                    
< div  align ="center" > 时间 </ div >
                                
</ td >
                                
< td  width ="45%" >< asp:TextBox  Runat ="server"  ID ="tbMeetDate"  Columns ="20"  Height ="23px" ></ asp:TextBox ></ td >
                            
</ tr >
                            
< tr >
                                
< td  class ="deep"  width ="13%" >
                                    
< div  align ="center" > 纪要整理 </ div >
                                
</ td >
                                
< td  width ="45%" >< asp:TextBox  Runat ="server"  ID ="tbRemarkPeople"  Columns ="20"  Height ="23px" ></ asp:TextBox ></ td >
                            
</ tr >
                            
< tr >
                                
< td  class ="deep"  width ="13%" >
                                    
< div  align ="center" > 始末时间 </ div >
                                
</ td >
                                
< td  width ="45%" >< asp:TextBox  Runat ="server"  ID ="tbStartToOver"  Columns ="20"  Height ="23px" ></ asp:TextBox ></ td >
                            
</ tr >
                            
< tr >
                                
< td  class ="deep"  width ="13%" >
                                    
< div  align ="center" > 人员 </ div >
                                
</ td >
                                
< td  width ="45%" >< asp:TextBox  Runat ="server"  ID ="tbToWho"  Columns ="38"  Height ="23px"  onclick ="javascript:alert('请点击右边图标添加')" ></ asp:TextBox >
                                    
&nbsp;&nbsp; < IMG  title ="选择人员"  style ="CURSOR: hand"  onClick ="window.open('../../common/selectUsers.htm','选择人员','width=700,height=350')"
                                        height
="16"  src ="../../WebPic/person1.gif"  width ="16" >  请点击左边图标,添加人员  < input  id ="tbToWhoId"  type ="hidden"  runat ="server"  style ="WIDTH:20px"  NAME ="tbToWhoId" ></ td >
                            
</ tr >
                            
< tr >
                                
< td  width ="20%"  colSpan ="2" > &nbsp; </ td >
                            
</ tr >
                        
</ table >
                    
</ td >
                
</ tr >
                
< tr >
                    
< td  align ="center" >< input  id ="iptSave"  name ="iptSave"  value ="保 存"  type ="button"  style ="WIDTH:58px;CURSOR:hand;HEIGHT:23px"
                            onclick
="javascript:SaveData();" >   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        
< input  id ="redirect"  type ="button"  name ="redirect"  style ="DISPLAY:none;WIDTH:98px;CURSOR:hand;HEIGHT:23px"
                            value
="添加会议事项"  onclick ="javascript:Redirect();" >
                    
</ td >
                
</ tr >
            
</ table >
        
</ form >

需要把代码服务器端控件改成客户端控件,性能有所提高!代码中有很多不足的地方望牛人们谅解,只是为了掌握Ajax.dll组件用法!

你可能感兴趣的:(.net)