calling a c#.net function from javascript
<p>I am creating an application using C#.net.<br/><br/>
I am trying to update my page as soon as data in the database is updated.<br/>
I have stored one value from the database in one label and i am calling a function each time which is storing the same value in another label and after that i am comaparing the two labels.<br/>The code is </p>

<p>my webpage.aspx.cs is </p>

<pre><code>public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        if (con.State == System.Data.ConnectionState.Closed)
        {
            con.Open();
        }
        SqlDataAdapter adp = new SqlDataAdapter("SELECT name from Master where id= 10"), con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        Label2.Text = Convert.ToString(ds1);
    }
    protected String CodeBehind()
    {
        SqlDataAdapter adp = new SqlDataAdapter("SELECT name from Master where id= 10"), con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        String ds2 = Convert.ToString(ds1);
        return (ds2);
    }
    protected int compare()
    {
        string abc = Label2.Text;
        string abcd = Label3.Text;
        if (abc == abcd)
        { 
            return(0);
        }
        else
        {
            return (1);
        }
     }
 }
</code></pre>

<p>and my front end javascript code is </p>

<pre><code> &lt;script type="text/JavaScript"&gt;
    function AutoRefresh() {
        document.getElementById('&lt;%= Label3.ClientID %&gt;').innerHTML = '&lt;%= CodeBehind() %&gt;';
        var res = '&lt;%= compare() %&gt;'
        if ( res == 1) {
            alert("same");
            setTimeout("location.reload(true);", 60000);
        }
        else {
         alert("different")
             abx();
         }
     }
     function abx() {
         AutoRefresh();
     }
</code></pre>

<p>But there is a problem as when i am calling the function codebehind, it is executing the whole backend code thus the value of both the labels is updated at the same time.
<br/><br/>I just want to call the code behind function every time and want to update the value of label2 just once.<br/><br/> can some tell me how can i do it.</p>
