Animated Gif while processing...http://forums.asp.net/t/1393626.aspx/1?Animated+Gif+while+processing+Tue, 17 Mar 2009 20:23:00 -040013936262986372http://forums.asp.net/p/1393626/2986372.aspx/1?Animated+Gif+while+processing+Animated Gif while processing... <p>&nbsp;I was wondering what the best approach would be to show an animated gif while I do some processing. I would assume threads would be involved, but Im looking for some good suggestions or tutorials... Thanks for your help!<br> </p> 2009-03-06T02:58:18-05:002986887http://forums.asp.net/p/1393626/2986887.aspx/1?Re+Animated+Gif+while+processing+Re: Animated Gif while processing... <p>Yes we have done it. for this u have to create a user control,basically this user control will be having a gif image of your loading and it will set its own position to the center of ther page...</p> <p>u have to place the control in the update progress panel on ur aspx page like this..</p> <font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">UpdateProgress</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;UpdateProgressItemList&quot;</font><font size="2"> </font><font color="#ff0000" size="2">AssociatedUpdatePanelID</font><font color="#0000ff" size="2">=&quot;panelListHotel&quot;</p> </font><font size="2"> <p></font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">ProgressTemplate</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">table</font><font size="2"> </font><font color="#ff0000" size="2">cellpadding</font><font color="#0000ff" size="2">=&quot;0&quot;</font><font size="2"> </font><font color="#ff0000" size="2">cellspacing</font><font color="#0000ff" size="2">=&quot;0&quot;</font><font size="2"> </font><font color="#ff0000" size="2">width</font><font color="#0000ff" size="2">=&quot;100%&quot;</font><font size="2"> </font><font color="#ff0000" size="2">border</font><font color="#0000ff" size="2">=&quot;0&quot;&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">tr</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">td</font><font size="2"> </font><font color="#ff0000" size="2">align</font><font color="#0000ff" size="2">=&quot;center&quot;&gt;</p> </font><font size="2"> <p></font><strong><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">uc1</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">LoadImage</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;LoadImage1&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">ContentHeight</font><font color="#0000ff" size="2">=&quot;100&quot;</font><font size="2"> </font><font color="#ff0000" size="2">ContentWidth</font><font color="#0000ff" size="2">=&quot;100&quot;&gt;</p> </font></strong><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">uc1</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">LoadImage</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">td</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">tr</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">table</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">ProgressTemplate</font><font color="#0000ff" size="2">&gt;</font></p> <p><font color="#0000ff" size="2"></font>&nbsp;</p> <p><font color="#0000ff" size="2">Here <strong><font color="#a31515">LoadImage</font><font color="#000000" size="2">&nbsp; is the user control... now i wil show u pierce of code wot we have done in the <font color="#a31515">LoadImage</font><font size="2">&nbsp; control</font></font></strong></font></p> <p><font color="#0000ff" size="2"><strong><font color="#000000">in the code behind</font></strong></font></p> <p><font color="#0000ff" size="2"><strong><font color="#000000"></font></strong></font>&nbsp;</p> <font color="#0000ff" size="2"><font color="#0000ff" size="2"> <p>public</font><font color="#000000" size="2"> </font><font color="#0000ff" size="2">partial</font><font color="#000000" size="2"> </font><font color="#0000ff" size="2">class</font><font color="#000000" size="2"> </font><font color="#2b91af" size="2">LoadImage</font><font color="#000000" size="2"> : System.Web.UI.</font><font color="#2b91af" size="2">UserControl</p> </font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">int</font><font size="2"> _contentWidth = 100;</font></font><font size="2"> <p></font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">int</font><font size="2"> _contentHeight = 100;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2"> _contentCSSClass = </font><font color="#a31515" size="2">&quot;loading_image_main&quot;</font><font size="2">;</font><font size="2"></font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2"> _backgroundCSSClass = </font><font color="#a31515" size="2">&quot;loading_image_black_overlay&quot;</font><font size="2">;</font><font size="2"> <p>&nbsp;</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">int</font><font size="2"> ContentWidth</font><font size="2"> <p>{</p> <p></font><font color="#0000ff" size="2">get</font><font size="2"> { </font><font color="#0000ff" size="2">return</font><font size="2"> _contentWidth; }</p> </font><font color="#0000ff" size="2">set</font><font size="2"> { _contentWidth = </font><font color="#0000ff" size="2">value</font><font size="2">; }</font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">int</font><font size="2"> ContentHeight</font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">get</font><font size="2"> { </font><font color="#0000ff" size="2">return</font><font size="2"> _contentHeight; }</font><font size="2"></font><font color="#0000ff" size="2">set</font><font size="2"> { _contentHeight = </font><font color="#0000ff" size="2">value</font><font size="2">; }</font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2"> BackgroundCSSClass</font><font size="2"> <p>{</p> <p></font><font color="#0000ff" size="2">get</font><font size="2"> { </font><font color="#0000ff" size="2">return</font><font size="2"> _backgroundCSSClass; }</p> </font><font color="#0000ff" size="2">set</font><font size="2"> { _backgroundCSSClass = </font><font color="#0000ff" size="2">value</font><font size="2">; }</font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2"> ContentCSSClass</font><font size="2"> <p>{</p> </font><font color="#0000ff" size="2">get</font><font size="2"> { </font><font color="#0000ff" size="2">return</font><font size="2"> _contentCSSClass; }</font><font size="2"></font><font color="#0000ff" size="2">set</font><font size="2"> { _contentCSSClass = </font><font color="#0000ff" size="2">value</font><font size="2">; }</font><font size="2"> <p>}</p> <p>&nbsp;</p> </font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> Page_Load(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#2b91af" size="2">EventArgs</font><font size="2"> e)</font><font size="2"> <p>{</p> <p>}</p> <p>&nbsp;</p> <p>and in the&nbsp; controls' aspx page place tihs code..only some javascript</p> <p>&nbsp;</p> <p>&lt; %@ Control AutoEventWireup=&quot;true&quot; Codebehind=&quot;LoadImage.ascx.cs&quot; Inherits=&quot;HotelBooking.App_Controls.UserControls.LoadImage&quot;<br> &nbsp;&nbsp;&nbsp; Language=&quot;C#&quot; % &gt;<br> &lt; !--div id=&quot;backgroundDiv&quot; style=&quot;height: 100%;&quot; &gt;<br> &lt; /div &gt;-- &gt;<br> &lt; %--&lt; div id=&quot;contentDiv&quot; &gt;<br> &nbsp;&nbsp;&nbsp; &lt; img alt=&quot;Loading&quot; src=&quot;App_Themes/Default/images/loader.gif&quot; / &gt;<br> &lt; /div &gt;--% &gt;<br> &lt; div id=&quot;contentDiv&quot; style=&quot;border: 1px solid rgb(192, 147, 56); position: absolute; display: block; top: 262.5px; left: 402.5px; background-color: rgb(248, 240, 203); width: 200px; height: 50px; color: rgb(192, 147, 56);z-index:1000;&quot; align=&quot;center&quot; &gt;<br> &nbsp;&nbsp;&nbsp; &lt; img src=&quot;App_Themes/Default/images/loader.gif&quot; alt=&quot;Please wait...&quot; id=&quot;imgBNWait&quot; style=&quot;text-align: center; padding-top: 15px;&quot; align=&quot;middle&quot; &gt;&lt; br &gt;Loading...<br> &nbsp;<br> &lt; /div &gt;</p> <p>&lt; script language=&quot;javascript&quot; type=&quot;text/javascript&quot; &gt;<br> /*call the function when the control loads.*/<br> //loadContentDiv('&lt; %=ContentWidth% &gt;', '&lt; %=ContentHeight% &gt;');<br> setCssClass('&lt; %=BackgroundCSSClass% &gt;', '&lt; %=ContentCSSClass% &gt;');</p> <p>function loadContentDiv(width, height)<br> {<br> /*&lt; img alt=&quot;Loading&quot; src=&quot;App_Themes/Default/images/loader.gif&quot; / &gt;*/<br> &nbsp;&nbsp;&nbsp; if (width != '' &amp;&amp; parseInt(width) != NaN)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width = parseInt(width, 10);<br> &nbsp;&nbsp;&nbsp; else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;Please provide valid Width.&quot;);<br> &nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; if (height != '' &amp;&amp; parseInt(height) != NaN)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height = parseInt(height, 10);<br> &nbsp;&nbsp;&nbsp; else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&quot;Please provide valid Height.&quot;);</p> <p><br> &nbsp; /* Fudge factors for window decoration space.<br> &nbsp;&nbsp; In my tests these work well on all platforms &amp; browsers.*/<br> &nbsp; var w = width &#43; 32;<br> &nbsp; var h = height &#43; 96;<br> &nbsp; var wleft = (screen.width - w) / 2;<br> &nbsp; var wtop = (screen.height - h) / 2;<br> &nbsp; <br> &nbsp; /* IE5 and other old browsers might allow a window that is<br> &nbsp;&nbsp; partially offscreen or wider than the screen. Fix that.<br> &nbsp;&nbsp; (Newer browsers fix this for us, but let's be thorough.)*/<br> &nbsp; if (wleft &lt;&nbsp; 0) {<br> &nbsp;&nbsp;&nbsp; w = screen.width;<br> &nbsp;&nbsp;&nbsp; wleft = 0;<br> &nbsp; }<br> &nbsp; if (wtop &lt;&nbsp; 0) {<br> &nbsp;&nbsp;&nbsp; h = screen.height;<br> &nbsp;&nbsp;&nbsp; wtop = 0;<br> &nbsp; }</p> <p>&nbsp; var objDiv&nbsp; = document.getElementById('contentDiv')<br> &nbsp; if (objDiv != null || String(objDiv) != &quot;undefined&quot;)<br> &nbsp; {<br> &nbsp;&nbsp;&nbsp; /* Set left and top of the content div*/<br> &nbsp;&nbsp;&nbsp; objDiv.style.left = wleft &#43; &quot;px&quot;;<br> &nbsp;&nbsp;&nbsp; objDiv.style.top = wtop &#43; &quot;px&quot;;<br> &nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; /* Set height and width of the content div*/<br> &nbsp;&nbsp;&nbsp; objDiv.style.width = width &#43; &quot;px&quot;;<br> &nbsp;&nbsp;&nbsp; objDiv.style.height = height &#43; &quot;px&quot;;</p> <p>&nbsp; }</p> <p>}</p> <p>function setCssClass(backClass, contentClass)<br> {<br> &nbsp;&nbsp;&nbsp; //var objBackDiv&nbsp; = document.getElementById('backgroundDiv');<br> &nbsp;&nbsp;&nbsp; var objContentDiv&nbsp; = document.getElementById('contentDiv');<br> &nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; /*set css class of the background div*/<br> //&nbsp;&nbsp;&nbsp; if (objBackDiv != null || String(objBackDiv) != &quot;undefined&quot;)<br> //&nbsp;&nbsp;&nbsp; {<br> //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objBackDiv.className = backClass;<br> //&nbsp;&nbsp;&nbsp; }<br> //&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; /*set css class of the content div*/<br> &nbsp;&nbsp;&nbsp; if (objContentDiv != null || String(objContentDiv) != &quot;undefined&quot;)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objContentDiv.className = contentClass;<br> &nbsp;&nbsp;&nbsp; }<br> }</p> <p>function SetBackgroundHeightOfLoadingControl(pageHeight)<br> {<br> &nbsp;&nbsp;&nbsp; var objBackDiv&nbsp; = document.getElementById('backgroundDiv');<br> &nbsp;&nbsp;&nbsp; /*if page height is not passed from the page*/<br> &nbsp;&nbsp;&nbsp; if (String(pageHeight) == &quot;&quot;)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objBackDiv.style.height = document.documentElement.getAttribute(&quot;scrollHeight&quot;) &#43; &quot;px&quot;;<br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; else<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objBackDiv.style.height = String(pageHeight) &#43; &quot;px&quot;;<br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; if(navigator.appName == &quot;Microsoft Internet Explorer&quot;)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objBackDiv.style.width = document.documentElement.getAttribute(&quot;scrollWidth&quot;);<br> &nbsp;&nbsp;&nbsp; }<br> }</p> <p>&lt; /script &gt;</p> <p>&nbsp;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#a31515" size="2">UpdateProgress</font><font color="#0000ff" size="2">&gt;</p> </font> 2009-03-06T07:28:37-05:002986953http://forums.asp.net/p/1393626/2986953.aspx/1?Re+Animated+Gif+while+processing+Re: Animated Gif while processing... <p>Hi,</p> <p><a href="http://www.asp.net/AJAX/Documentation/Live/overview/PartialUpdates.aspx">http://www.asp.net/AJAX/Documentation/Live/overview/PartialUpdates.aspx</a></p> <p>Hope The Above Sample Help You..</p> 2009-03-06T08:00:27-05:002994848http://forums.asp.net/p/1393626/2994848.aspx/1?Re+Animated+Gif+while+processing+Re: Animated Gif while processing... <p>Hi gmcalab,<br> <br> Using the UpdateProcess is a good choice. The gif picture can be placed inside the UpdateProcesss ProcessTemplate directly. <br> <br> Here is my sample code:</p> <p>.aspx file&nbsp;</p> <blockquote><pre class="prettyprint">&lt;%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; CodeBehind=&quot;TestGifInProgress.aspx.vb&quot; Inherits=&quot;UpdateProgress.TestGifInProgress&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt; &lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt; &lt;ContentTemplate&gt; &lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text=&quot;Label&quot;&gt;&lt;/asp:Label&gt; &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot; /&gt; &lt;asp:UpdateProgress ID=&quot;UpdateProgress1&quot; runat=&quot;server&quot; AssociatedUpdatePanelID=&quot;UpdatePanel1&quot;&gt; &lt;ProgressTemplate&gt; &lt;asp:Image ID=&quot;Image1&quot; runat=&quot;server&quot; ImageUrl=&quot;~/fun.gif&quot; /&gt; &lt;/ProgressTemplate&gt; &lt;/asp:UpdateProgress&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre></blockquote>.aspx.vb file&nbsp;<blockquote><pre class="prettyprint"><span class="kwd">Public</span> Partial <span class="kwd">Class</span> TestGifInProgress <span class="kwd">Inherits</span> System.Web.UI.Page <span class="kwd">Protected Sub</span> Button1_Click(<span class="kwd">ByVal</span> sender <span class="kwd">As Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> EventArgs) <span class="kwd">Handles</span> Button1.Click <span class="cmt">', Timer1.Tick</span> System.Threading.Thread.Sleep(3000) Label1.Text = <span class="kwd">Date</span>.Now.ToString <span class="kwd">End Sub End Class</span></pre></blockquote> The related tutorial: <a href="http://www.asp.net/learn/ajax-videos/video-123.aspx"> http://www.asp.net/learn/ajax-videos/video-123.aspx </a><br> <p><br> Best regards,<br> <br> Zhi-Qiang Ni<br> <br> </p> 2009-03-10T02:25:10-04:003014196http://forums.asp.net/p/1393626/3014196.aspx/1?Re+Animated+Gif+while+processing+Re: Animated Gif while processing... <p>&nbsp;Thanks all three of you for your great examples. This helped me very much!<br> </p> 2009-03-17T20:23:00-04:00