Kameron
Kameron

Reputation: 733

ASP.NET response after processing time

I have come across quite a wired problem right now.

I am using ASP.NET in Visual Studio 2010. Now I have a huge processing plus network integration to do when the user clicks a button. Point saying is that it takes a lot of time (about 1-1.5 minutes) for the response. Till then, i have to tell the user to be patient and do not refresh the page. I tried this as the first line of buttons :

label.visible=true;//label is initially set to invisible and has text that says user to be patient.

NO LUCK!!!

Next I also tried Response.Write("alert('Please be patient.')");

NO LUCK!!!

It is not that these statements are not executed. They are! But there are actually done after the processing time is over. i.e. user is told to be patient after the operation is done!

I know there is some concept called autopostback, but i can't find a method that allows autopostback of a label or an instruction. Can anyone save my day???

Upvotes: 0

Views: 254

Answers (3)

freefaller
freefaller

Reputation: 19953

You probably need to look at some javascript on the client, that is run at the point the user initiates this process. If (for example) you are initiating the process via a normal asp:Button then put in something like...

<asp:Button runat="server" id="btnInitiate" OnClientClick="document.lblPleaseWait.style.display='';return true;" Text="Initiate"/>
<asp:Label runat="server" id="lblPleaseWait" style="display:none;">Please Wait</asp:Label>

I know nothing about jquery, but I'm led to believe that would give you much better access to the label object within the DOM.

You might also want to disable the btnInitiate button to stop them repeat clicking. For this you'd need to investigate the UseSubmitBehavior="false" property

(Also, you misunderstand the "autopostback" property. It means that the control - when changed / clicked / etc - will automatically post back the form to the server. It is nothing to do with the response back from the server.)

Upvotes: 1

Vano Maisuradze
Vano Maisuradze

Reputation: 5899

This is all what you have to do:

 <asp:Button ID="btnClick" OnClientClick="showMessage()" runat="server" Text="Click" onclick="btnClick_Click" />
 <span style="display:none;" id="lblMessage">Please be patient.</span> 

showMessage() is javascript function, which should change lblMessage's display style:

<script type="text/javascript">
    function showMessage() {
        document.getElementById('lblMessage').style.display = 'block';
    }
</script>

Or, Instead of span, you can also use ASP.Net label control, but you must set its ClientIdMode attribute to Static:

<style type="text/css">
.InvisibleStyle
{
    display: none;    
}
</style>

<asp:Button ID="btnClick" OnClientClick="showMessage()" runat="server" Text="Click" onclick="btnClick_Click" />
<asp:Label ID="lblMessage" runat="server" Text="Please be patient." ClientIDMode="Static" CssClass="InvisibleStyle" ></asp:Label>

Upvotes: 1

mamoo
mamoo

Reputation: 8166

If, as I guess, you're in a postback paradigm that means that you fire the process, and the user gets the first response only after 1 min. or so. In between you cannot send anything to the user over the same request. A workaround could be to fire the event using ajax, so that you can fire the event asynchronously, show the courtesy message to the user, and wait for the response.

Upvotes: 1

Related Questions