Avatar of Elite_Bigfoot
Elite_Bigfoot
 asked on

ASP.NET AJAX Change a textbox two times through one lifecycle

Hello,

I would like my button to change a textbox two times during one lifecycle, Meaning,
When I click it, I would like first to see in the textbox - "start" and then after a few seconds "end"
However, with my following I only get "end" after the loop ends (take few seconds)

I understand that's how ajax lifecycle works, is there any way someone could suggest to manipulate it?

This is my code:
    <asp:UpdatePanel ID="upResult" runat="server">
        <ContentTemplate>
                        <asp:TextBox runat="server" ID="Date" Width="50px"/>
                       <asp:Button ID="Button" runat="server" Text="Button" onclick="Button_Click" />
      </ContentTemplate>
    </asp:UpdatePanel>

    protected void Button_Click(object sender, EventArgs e)
    {
        Date.Text = "start";        

        int i=0;
        while (i < 1000000000)
        {
            i++;            
        }

        Date.Text = "end";      
    }


Thanks a lot!
ASP.NETWeb ApplicationsC#

Avatar of undefined
Last Comment
Elite_Bigfoot

8/22/2022 - Mon
Todd Gerbert

Use OnClientClick to start a client-side timer in JavaScript.
McExp

It is not possible to have two postbacks for one request, this applies if you are using AJAX or not. Every request has only one response.

One solution would be to set the start text from the client side. Then do your serverside action and set the end text.

or

If the operation requires server side processing you could set a Javascript timer on the client side, do a postback and then on the next timer event do another postback, posibly repeating until a vaild response is recived?
Elite_Bigfoot

ASKER
I need the solution to be completly Server side, with no javascript involve.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Todd Gerbert

There's an animation extender in the AJAX toolkit, which might be useful - although AJAX is ultimately JavaScript anyway...
McExp

But you are using AJAX, which, I'm guessing you are aware of stands for Asynchronous JavaScript and XML, so your AJAX based solution is already using plenty of javascript.

A non Javascript based solution is not possible, as I said every request can have one and only one Response, even when using AJAX.
Elite_Bigfoot

ASKER
I mean a way to do it through some server side coding, less writing the actual java myself.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
McExp

There is an asp:Timer in the ajax extensions. you can use this, on the first postback you can enable the timer which will peroidically postback getting the progress until it's 100% complete then the timer can be disabled
Elite_Bigfoot

ASKER
Show me some code please.
McExp

Ok, going forward, the correct way to handle a long running process would be to use WPF, see here for an example

http://www.odetocode.com/Articles/465.aspx
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
McExp

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Elite_Bigfoot

ASKER
I'm not looking for a progress bar solution.

What I need is a way, to change some text before the process runs and after.

Please provide me an example.

I have read  the above articles, too much information with no real answer to my question.
McExp

Ok, So the only solution that can be produced in any sensible time frame.

Add some code to update a Label using Javascript and hook to the OnClientClick and then set the label again from server side which will update after the server side code completes
Elite_Bigfoot

ASKER
No possible other methods available?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Todd Gerbert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Elite_Bigfoot

ASKER
Thanks, however only partially helped me.