2

I write a countdown timer in jQuery and i need to keep some datas in a session when countdown ends. Datas have to be sent to server to update. How can i handle this situation. I am new in jQuery and asp.net so could you explain this briefly

abatishchev
  • 98,240
  • 88
  • 296
  • 433
boraer
  • 389
  • 4
  • 13

4 Answers4

0

If it's a one-way communication probably the quickest way is to call an aspx page using the $.get method:

http://api.jquery.com/jQuery.get/

something like this:

$.get('mypage.aspx', myData , function(result) {
   alert('Ok');
});

where myData is a JSON object.

for more specific needs you can use the $.ajax method.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
mamoo
  • 8,156
  • 2
  • 28
  • 38
0

Try using a PageMethod. You can create it in your codebehind and call it with jQuery. It's really fast & and great for countdown timers.

Make sure you enable PageMethods in your scriptmanager.

Call ASP.NET PageMethod/WebMethod with jQuery - returns whole page

Community
  • 1
  • 1
Ed B
  • 6,028
  • 3
  • 26
  • 35
0

It will be two-way communication both client and server have to communicate each other.

Echilon
  • 10,064
  • 33
  • 131
  • 217
boraer
  • 389
  • 4
  • 13
0

Supose you have a class like this:

public class MyClass
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

And an action method like this:

public JsonResult Test(string data)
    {
        // do something with data
        var obj = new MyClass {FirstName = "Thiago", LastName = "Temple"};
        return Json(obj);
    }

Then you can write a js function using jquery like this:

$.get('<%= Html.Action("Test", "MyController")', {data: "some value"}, function(result){
      alert(result.FirstName + " " + result.LastName);

});

I hope this example is useful.

thitemple
  • 5,833
  • 4
  • 42
  • 67