Mega Code Archive

 
Categories / Delphi / .NET
 

Delphi.NET display a wait while page loads... message in a web page

Title: Delphi.NET display a "wait while page loads..." message in a web page Question: when working with web pages sometimes the processing may take a long time on the server side, and all that time the user can't be updated like in a Windows application where can put a StatusBar or a ProgressBar... Normally when the user clicks a button or a Button Link, they just see the small progress bar (in Internet Explorer) and that's all they get indicating that the page is being requested, we can change that by adding some friendly message Answer: to do this we need to use a scripting language like javascript, because this has to be done on the Client Side I setup a form (FlowLayout) with - A table (to arrange the html items easily) - a HTML control button - a ServerControl LinkButton with it's Text property emtpy so it doesn't display on the browser (client side) - a "DIV" section in one of the cells of the table (where we will put the "wait" message) body ms_positioning="FlowLayout" form id="myForm" runat="server" table style="Z-INDEX: 4; LEFT: 6px; POSITION: absolute; TOP: 38px" cellspacing="1" cellpadding="1" width="300" border="1" tbody tr tdinput id="button1" style="Z-INDEX: 3" onclick="javascript:document.all.WaitDiv.innerHTML = 'Wait while the page loads...'; __doPostBack('SubmitLinkBtn','');" type="button" value="Submit" name="button1" /td /tr tr td asp:LinkButton id="SubmitLinkBtn" style="Z-INDEX: 2" runat="server"/asp:LinkButton /td /tr tr td div id="WaitDiv" /div /td /tr /tbody /table asp:LinkButton id="LinkButton1" runat="server"LinkButton/asp:LinkButton /form /body from the HTML button control, add the OnClick event (using javascript or vbscript): onclick="javascript:document.all.WaitDiv.innerHTML = 'Wait while the page loads...'; __doPostBack('SubmitLinkBtn','');" and what that does is it changes the "DIV" section you had empty, puts the "wait while the page loads" message, and then executes __doPostBack sending SubmitLinkBtn as the sender, to make the server side think that the user actually clicked on the server control button, which then allows you to execute code on the server side I added a OnClick event to the SubmitLink server control to demonstrate that it works as expected procedure TWebForm1.SubmitLinkBtn_Click(sender: System.Object; e: System.EventArgs); begin Sleep(1000); if (IsPostback) then Response.Write('Posted from the server'); end; when the entire page is rendered to the user again, this code in the .aspx file div id="WaitDiv" /div allows to message to clear itself Notes: Using javascript you could do much more, you could hide the entire page or the buttons if you wanted so the user doesn't click anywhere else while the request is being processed and display something else, this is just an example of what can be done for example you may have seen some pages that disable the button you clicked so you don't click it twice, and then return the results, this can be achieved using the same technique Summary: Using HTML controls allow you to have control on the client side (browser) and invoke server side controls using javascript, which then will allow your application to execute code on the server side keep checking here for more articles about delphi.NET hope this helps you, comments are welcome best regards EberSys