pragan
pragan

Reputation: 13

Calling a server side function using a Javascript

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?

Upvotes: 0

Views: 768

Answers (4)

Arion
Arion

Reputation: 31239

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
}

Upvotes: 0

Darren
Darren

Reputation: 70728

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 {

            }
        }
    });
}

Upvotes: 1

Mohit
Mohit

Reputation: 11314

set

ddl.autopostback = true ;

and fire selectedindexchange event

Upvotes: 1

Paul Grimshaw
Paul Grimshaw

Reputation: 21034

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.

Upvotes: 0

Related Questions