调用服务器端方法和客户端端方法 [英] Call server side method and clients side method

查看:90
本文介绍了调用服务器端方法和客户端端方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 早上好!!!
我有问题.我想同时在dropdownlist上的Selected Index上调用一个服务器端方法和一个Javacsript方法.如果acll clent side方法然后不使用acll服务器端方法.请帮助

Hi Good morning!!!
i Have a problem .i wanna call a sever side method and one Javacsript method on Selected index change on dropdownlist on same time.if acll clent side method then not acll sever side method.please help

推荐答案

我认为可以.另外,您必须决定先执行哪个.

1.创建下拉菜单
2.在客户端处理更改事件,并调用类似OnChange()的函数;
3.在此onchange函数中,调用您的客户端函数.
4.在同一函数中,使用XMLHttpRequet或jQuery AJAX调用服务器端函数.

以下文章已经描述了如何调用服务器端函数

面向初学者的AJAX(第2部分)-使用XMLHttpRequest和jQuery AJAX实施级联下拉列表 [ ^ ]

我建议您进行一些小的更改,例如:[上一篇文章的代码片段,有关详细信息,请参考.]

I think you can. althogh you will have to decide which one will be executed first.

1. create the dropdown
2. handle the change event on client side and call a function like OnChange();
3. in this onchange function call your client side function.
4. in the same function call the server side function using XMLHttpRequet or jQuery AJAX.

the following article already decribes how to call server side function

AJAX for beginners (Part 2) - Using XMLHttpRequest and jQuery AJAX to implement a cascading dropdown[^]

I suggest you make a small change like: [Code snippet from above article, refer that for details.]

function onChange()
{ 
    //call your client side method here
   
    //create the ajax request to call server side method


.ajax ( { 类型:" // HTTP方法 网址:" // 页面/方法名称 数据:" +
.ajax ( { type: "POST", //HTTP method url: "Default2.aspx/OnContinentChange", //page/method name data: "{'continentName':'"+


(' #drpContinent').val()+ " '}" json转换为代表论点 contentType:" , dataType:" , 成功:回调, 错误:onError } ); }
('#drpContinent').val() +"'}", //json to represent argument contentType: "application/json; charset=utf-8", dataType: "json", success: callback, error: onError } ); }


这篇关于调用服务器端方法和客户端端方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆