Sun_china

交流更多,收获更多?

博客园 首页 新随笔 联系 订阅 管理
  1具体使用: 
  2
  3
  4
  51. 在项目中添加引用Ajax.dll (我用的版本是5.7.22.2) 
  6
  7
  8
  92. 修改web.config,在里面增加 
 10
 11
 12
 13<configuration>
 14  <system.web>
 15    <httpHandlers>
 16    <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
 17    </httpHandlers>  
 18     
 19  <system.web>
 20</configuration> 
 21
 22
 23
 24
 25 
 26
 27
 283. 新建一个实现业务逻辑的类,并在里面增加方法,在方法上面加上[Ajax.AjaxMethod()]。如: 
 29
 30
 31
 32    /// <summary> 
 33
 34
 35
 36     /// 业务逻辑的类 
 37
 38
 39
 40     /// </summary> 

 41
 42
 43
 44     public class AjaxBLLClass 
 45
 46
 47
 48     
 49
 50
 51
 52         public AjaxBLLClass() 
 53
 54
 55
 56         {             
 57
 58
 59
 60         }
 
 61
 62
 63
 64         [Ajax.AjaxMethod()] 
 65
 66
 67
 68         public string GetPlaceList(int ClassID) 
 69
 70
 71
 72         
 73
 74
 75
 76              Advertisement.BLL.ADManage.AdPlace adplace=new Advertisement.BLL.ADManage.AdPlace(); 
 77
 78
 79
 80              DataSet ds=adplace.GetListByClass(ClassID); 
 81
 82
 83
 84              string str=""
 85
 86
 87
 88              for(int m=0;m<ds.Tables[0].Rows.Count;m++
 89
 90
 91
 92              
 93
 94
 95
 96                   str+=","+ds.Tables[0].Rows[m]["PlaceID"].ToString()+"|"+ds.Tables[0].Rows[m]["PlaceName"].ToString(); 
 97
 98
 99
100              }
 
101
102
103
104str=str.Substring(1,str.Length-1); 
105
106
107
108return str; 
109
110
111
112         }
 
113
114
115
116         
117
118
119
1204. 在调用页的.cs的Page_Load事件中增加一行类注册代码 
121
122
123
124private void Page_Load(object sender, System.EventArgs e)
125 {
126   //注册类获得有效的方法
127   Ajax.Utility.RegisterTypeForAjax(typeof(AjaxBLLClass));
128  }

129
130
131
132
133注意:typeof(AjaxBLLClass)中,AjaxBLLClass是要包含要调用方法的类,即上面第3步新建的业务逻辑类AjaxBLLClass 
134
135
136
1375. 在调用页页面文件中或者单独写一个js文件,用Javascript代码调用业务逻辑的类的方法。如: 
138
139
140
141              function classResult() 
142
143
144
145         
146
147
148
149              var classid=document.getElementById("DropClassID"); 
150
151
152
153              AjaxBLLClass.GetPlaceList(classid.value,get_class_Result_CallBack);//调用业务逻辑类方法 
154
155
156
157              
158
159
160
161         }
 
162
163
164
165
166 
167
168
169         function get_class_Result_CallBack(response) 
170
171
172
173         
174
175
176
177              if (response.value != null
178
179
180
181              {                    
182
183
184
185                   document.getElementById("DropPlaceID").length=0
186
187
188
189               var piArray = response.value.split(","); 
190
191
192
193          for(var i=0;i<piArray.length;i++
194
195
196
197          
198
199
200
201             var ary1 = piArray[i].toString().split("|"); 
202
203
204
205             document.getElementById("DropPlaceID").options.add(new Option(ary1[1].toString(),ary1[0].toString())); 
206
207
208
209          }
                     
210
211
212
213              }
                
214
215
216
217              return 
218
219
220
221         }
 
222
223
224
2256. 调用 
226
227
228
229<asp:dropdownlist id="DropClassID" runat="server" Width="250px" onchange=” classResult()”></asp:dropdownlist> 
230
231
232
posted on 2007-05-15 15:23  Sun_china  阅读(678)  评论(0编辑  收藏  举报