2

How to do it? I am completely new to this and wish to start learning it. I am going to have a tree structure, most probably a html/Javascript tree which will need to be saved into the database through Web Services.

What is the most efficient way to do this with ASP .net web services + asp.net 3.5?

UPDATED: thanks for all the answers, I am still missing some pieces to this scenario, namely: 1) when the node is to be added to the tree, a user will get a pop-up, where some info will be entered, saved in the database, and a integer code returned from the database. Upon it's return, I need do some logic, and insert a node(or several) into the node selected. And so on, so forth. SO from what i understand, this logic (the meat of the code) will have to be performed on the client, in my Javascript code. 2) What would trigger the tree "refresh" after the pop-up is closed? 3) Where is .net with this picture at all? From what I gather, no server-side coding is performed here at all (aside from Web Services). Is that the general direction these days, step away from server-side coding with .net controls and use a Javascript lib of choice + web services?

Thanks everyone.

4 Answers 4

4

You can achieve this by using ASP.net Ajax calls. On the server-side you create a webservice (WCF or asmx) having the attribute ScriptService:

namespace MyCompany.Project.Services
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService]
    public class MyWebServiceClass : System.Web.Services.WebService
    {

        [WebMethod]
        public string GreetFromServer(string name)
        {
            return "Hello, " + name;
        }
    }
}

On the page, you add a ScriptManager referencing your webservice.

<asp:ScriptManager id="scriptManager" runat="server">
   <Services>
      <asp:ServiceReference Path="~/Services/MyWebServiceClass"/>
   </Services>
</asp:ScriptManager>

Then on the client side (JavaScript):

function invokeService(){
   MyCompany.Project.Services.MyWebServiceClass.GreetFromServer("Juri", onSuccess, onFailure);
}

function onSuccess(result){
  //check if result different null etc..It will be in JSON format, so deserialize
  //use result
}

function onFailure(){
   //handle errors
}

That should just be a hint on how to create a service and access it from within JavaScript. I mostly wrote it out of my head now, without checking it.
A hint: use Firebug! It's really great for verifying the data that is sent back and forth between your JavaScript client code and the webservice on the server-side.

I've just written a blog post with a downloadable example that describes the communication of client-server using asmx as well as WCF webservices.

Sign up to request clarification or add additional context in comments.

1 Comment

I just added a link to a blog post I've written related to this issue.
1

Encosia.com has everything you need:

Using jQuery to Consume ASP.NET JSON Web Services

2 Comments

thanks, I however am still unclear on this part: on form submit, someone is going to have to write code on the client to collect that data and send it via Ajax to a server method. From what i heard, Jquery doesn't play well with Asp.net. Is it old news? How am i going to trigger the page to refresh (call the server method via Ajax) with Jquery? none of these links tell me how to do that.
Jquery will play very well with asp.net weblogs.asp.net/scottgu/archive/2008/09/28/…
0

I would suggest you use jquery on the client side in your html / Javascript tree. Here is a tutorial to get you started on using jquery with asp.net

http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx

1 Comment

yes, but can I consume asp.net web services from within Jquery? I only found one resource on how to do it: geekswithblogs.net/shahed/archive/2009/07/11/133402.aspx and it looks like a pain. Any experiences with that?
0

Have a look

Consuming a Web Service using ASP.NET Ajax

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.