From what I have understand, a CallBack to the backend code would not cause the page to reload(like a PostBack would). However, I don't know how to acplish a CallBack from my client side JavaScript.
Or is there an alternative way to run a backen function only once?
From what I have understand, a CallBack to the backend code would not cause the page to reload(like a PostBack would). However, I don't know how to acplish a CallBack from my client side JavaScript.
Or is there an alternative way to run a backen function only once?
Share Improve this question asked Oct 27, 2011 at 9:12 NaningNaning 7342 gold badges8 silver badges18 bronze badges 1- Take a look at jQuery's ajax, post and get method calls. – Andy Rose Commented Oct 27, 2011 at 9:14
3 Answers
Reset to default 2http://api.jquery./jQuery.ajax/
Have a look at this article by Dave Ward -
http://encosia./using-jquery-to-directly-call-aspnet-ajax-page-methods/
It takes you through the process of setting up a call from jQuery to c# step-by-step
When you create an HTML object such as HTML Button add runat="server" as attribute, ASP .NET will create a javascript function __doPostBack. You can use this function to call server object.
<html>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblCounter" runat="server" Text="Counter:"></asp:Label>
<br />
<br />
<input id="btnAddCounter" type="button" value="Add Counter" runat="server" />
<br />
<br />
<a onclick="__doPostBack('btnAddCounter','')" style="cursor: pointer;">Invoke Postback (it's just like push the Button)</a>
</form>
</body>
</html>
the code behind:
Partial Class test_testpostback
Inherits System.Web.UI.Page
Shared counter As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblCounter.Text = "[This will display counter]"
End Sub
Protected Sub btnAddCounter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddCounter.ServerClick
counter = counter + 1
lblCounter.Text = "Counter: " & counter
End Sub
End Class