views:

56

answers:

4

Hi everybody,

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

A: 

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.

mamoo
A: 

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.

http://stackoverflow.com/questions/583116/call-asp-net-pagemethod-webmethod-with-jquery-returns-whole-page

Ed B
A: 

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

boraer
A: 

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.

VinTem