Update label dynamically with jquery ajax

Posted on 2008-10-22
Last Modified: 2012-08-13
Hello experts,

I have an page that on the Page_Load method takes some value from the database and then assigns it to an Label.

<asp:Label ID="ResultLabel1" runat="server"></asp:Label>

protected void Page_Load(object sender, EventArgs e)
resultText = ...
ResultLabel1.Text = resultText;

This value is being dynamically changed on the background, but unfortunately the only way right now to update this value is to manually reload the whole page.

I would like to implement ajax request using jquery in order to update that value on the page dynamically (let's say once in a minute) without manual reloading the whole page.

I figured out that with jquery I can use $.get to get the same page and somehow parse the returned html. I'm new to jquery and javascript itself, so unfortunately I cannot get any further...

Any ideas?
Question by:snarinsky
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22779875
To get the client element from a ASP.NET server control use can use it's ClientID property.
In order to change the text of your label you can use :

$("#<%= ResultLabel1.ClientID %>").text("New text");
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22779885
NB This is jQuery so Clientside scripting

Author Comment

ID: 22780024
Ok thanks, but how can get the value of this label from the returned page?

My idea (I'm not sure if it's right) was to do something like the following:

            "<current page>",                 // Somehow I need to figure out how to get current url??
                $("#<%= ResultLabel1.ClientID %>").text("<updated value from the returned page>");      //Somehow I need to parse html of the returned page and get the new value of the ClientID label to reassign it here????
LVL 19

Accepted Solution

Albert Van Halen earned 500 total points
ID: 22780652
So, you want to process a complete page just in order to return a specific value which is displayed in a label.
Perhaps it's better to create a handler in ASP.Net (a file with the extension ashx).
This handler will function like a classic asp page, and will return just whatever you want (ie a specific value from the database), without all the overhead of a aspx page without to extract a certain value from the page which is rendered.
Keep in mind that a handler is a standalone page and will rely on the input you are sending to it in order to process things.

Usefull link, or just google on " ashx file"

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question