Calling a server side function using a javascript

安稳与你 提交于 2019-12-20 07:28:15

问题


I need to invoke a server side function when an item is picked in an ASP drop-down box, Can someone please tell me how to do that?


回答1:


Within ASP.NET use the drop down selected index change event. Alternatively for a client side event you could use JQuery and then use the following JavaScript function to contact the Server:

function CallServer() {
    $.ajax({
        url: 'webserviceURL',
        type: "POST",
        datatype: "json",
        success: function (result) {
            if (result.Success) {

            } else {

            }
        }
    });
}



回答2:


set

ddl.autopostback = true ;

and fire selectedindexchange event




回答3:


Add a web service to your project, and have this perform the actions/return the data you need on the client. Then use AJAX (or JQUERY AJAX) to call this service when needed.




回答4:


You can do it like this:

Aspx

<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" 
OnSelectedIndexChanged="ddl_SelectedIndexChanged"></asp:DropDownList>

CS

protected void ddl_SelectedIndexChanged(Object sender, EventArgs e) 
{
    //call your function
}


来源:https://stackoverflow.com/questions/9908210/calling-a-server-side-function-using-a-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!