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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimAuthor 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.
TimAuthor 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.
TimAuthor 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);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.