Updating ASP.NET page in real time


User types in information into a multiline textbox and hits search. My c#code is executed and begins my search function based on what the user types in.

If the client types in 10 things my code will look through those ten things one by one and output the search results to the asp page table as they are completed.


The results do not show on the page until all 10 results are completed. I am trying to have the results shown as they get completed and not have to wait until after my code is finished working.

I looked into using a timer.But I am unsure how to grab the results from the timer function And update my table.

Who is Participating?
käµfm³d 👽Commented:
You cannot use a timer. You need to understand the basics of how the web works. Once you understand the basics, then it should be apparent why a timer won't work.

What you will need to do instead is to look into either AJAX or SignalR/websockets. An AJAX approach is workable, but could get messy quickly. The SignalR approach would probably be more appropriate. Unfortunately, I do not have experience with SignalR yet, so I would be hard-pressed to provide you with an example. It should be easy enough to find tutorials on the web, though.
tr57285Author Commented:
Thanks. I have been looking into SignalR. It appears to be client side jquery code. I am trying to learn how to use it and implement it.
tr57285Author Commented:
I also came across AJAX Long Polling which sends a request to the server for the data and waits (a specified amount of time) for the data before sending another request.

I am wondering if this would be better for me in this instance since I only want to update this one table on one page and not update a centralized object which everyone sees.

Would AJAX Long Polling be a better idea in this scenario?

käµfm³d 👽Commented:
I have to confess that I haven't yet used either--no business requirements to do so. My understanding is that the preferred approach is to use websockets when they are available as long polling is kind of hack-ish. I also understand that SignalR falls back to long polling if websockets are not available.
tr57285Author Commented:
So I was able to piece this together using examples I found online for AJAX Long Polling, but its still not working, wondering if someone can find the error of my ways.

Couple of questions:

1). What should "URL" be pointing to? Should it be the page calling the long poll or something else?
2). I am trying to update my table with id "Table2" and I am using the append function, but I am not understanding what data the poll is getting back. Is it getting back the output from my C# Behind code or it something else? My C# code constructs a row and adds it to the "Table2" table in my ASP.net page.

        <script type="text/javascript" src="Scripts/jquery-1.11.3.min.js" ></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#button1').click(function () {
                    (function poll() {
                        setTimeout(function () {
                                url: "/1.aspx", success: function (data) {
                                }, dataType: "json", complete: poll
                        }, 8000);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.