0

I use asp.net webform. But I am confused that how to send data between project?

This is project structure in sam solution

  • UI
  • BSClass(Business Class)

I used google to search for this solution but I didn't find.

Is it possible to send data by jQuery.post() from UI to Bussiness class? and How?

example Send Username and Password From UI to UserClass in BSClass

Thank you very much _/\_

Pradeep
  • 3,258
  • 1
  • 23
  • 36
Zabahey
  • 328
  • 1
  • 3
  • 16

2 Answers2

0

Have a look at the articles referenced in the answer to this question:

Using jQuery for ajax with asp.net webforms

Community
  • 1
  • 1
Rune
  • 8,340
  • 3
  • 34
  • 47
0

You won't be able to post directly to Business Class. I am assuming here that your business class is somewhere in middle and not the very first layer interacting with customer.

What you need to do is expose some method of your code behind as:

 [WebMethod]
 public static void UpdateName(string firstName, string lastName)
 {
   //do something here
 }

You need to decorate this method with [WebMethod] attribute and keep it static as well.

And then call this method from jQuery either via jQuery.ajax or jQuery.post method. Following is one snippet how you can use jQuery.ajax:

var dataString = "{'firstName':'" + firstName + "','lastName':'" + lastName + "'}";

jQuery.ajax({
   type: "POST",
   url: "Default.aspx/" + operation,
   contentType: "application/json; charset=utf-8",
   data: dataString,
   dataType: "json",
});

Exposing code behind methods as [WebMethod] is quick and dirty way. In a long term you should figure out and develop your web services with Ajax in scope and directly call web services for any data retrieval or update.

HTH

Pradeep
  • 3,258
  • 1
  • 23
  • 36