0

I have a method in my Default.aspx page and I would like to know how can I call this method every 5 seconds through JavaScript ?

protected void GetSlideNumber()
{
    var repos = new PresentationService();
    int slide = repos.GetSlideNumber();

    ceckSlide.Text = slide.ToString();

}
1
  • what do u actually mean Commented Feb 12, 2013 at 11:37

4 Answers 4

0

Make this method as [WebMethod] and use AJAX to all this method

$.ajax({
  type: "POST",
  url: "PageName.aspx/MethodName",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Do something interesting here.
  }
});

Refer Web Method
More information here

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

Comments

0

Use AJAX it can help you. More information can be found at this link.

$.ajax({ type: "POST", 
        url: pageMethod,
        data: "",
        success: function (result, status) {
        alert("success");
    },
    error: function (xhr, status, error) {
        alert("ERROR");
    }

    });

2 Comments

He wants to invoke aspx method from JS and not vice-versa
@asifsid88 Fixed my answer, any chance of getting downvote removed?
0

like below..

<script>
   window.setInterval(function(){
       GetSlideNumber()
   }, 1000);
</script>

4 Comments

how would i call the method above
I have edited above code..
this brakes and does not run
it says undefined method
0

Try this..

<script>
function sample()
{
alert("<%=GetSlideNumber()%>");
} 
</script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.