eli chen
eli chen

Reputation: 878

ajax in asp.net via scriptmanger

first of all forgive me my poor english it's not my lang.

I am trying to work with ajax as follows:

I created a webservice and a web page that calls to a method in the webservice. I am trying to call the service like this:

<button onclick="run()" formmethod="post">Sample</button>

The problem is that if this button is inside the form, it doesn't work because it posts back. If the button is outside of the form it works.

How can I put this button inside the form and still have it call the web service?

Upvotes: 0

Views: 62

Answers (1)

Pow-Ian
Pow-Ian

Reputation: 3635

I am thinking the problem is the button initalizes a submit before the service is called.

What I would suggest would be to use an input button and handle the click event:

<input type='button' onclick='CallService();' value='Sample' id='btnSample' />

in your script have:

function CallService(){
    {ServiceName}.run({parameter},CallComplete);
}

function CallComplete(){
    document.form.submit();
}

I would say do it this way so that you know your service is being called before the form is submitted.

Upvotes: 1

Related Questions