2014-02-23 102 views
2

我在學習Asp.Net之後,寫了一個母版頁後,我無法讓它在客戶端上運行(實際看到動畫)。線程等待操作是在發佈網頁之前在服務器上完成的,因此動畫不是動態的。它只顯示頁面的最終狀態。Asp .Net客戶端動態文本

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
</head> 
<body bgcolor="red"> 
<center> 
    <h2>Hello w3schools!</h2> 
    <h4 id="aa">qq</h4> 
    <h3> 

     <p><% 


      for (int i = 0; i < 30; i++) 
      { 
       System.Threading.Thread.Sleep(25); 
       int txtLeft = 300 + (int)(100*Math.Sin(i)); 
       int txtTop = 300+(int)(100*Math.Cos(i)); 
       string theText = "Hello there!"; 
       Response.Write("<div style=\"position:absolute; left: "+ txtLeft + "px; top:" + txtTop + "px; \">" + theText +"</div>"); 
      } 

      %></p> 


    </h3> 
</center> 
</body> 
</html> 

我試圖

RUNAT = 「客戶端」(附近的 「P」 字母是在括號中)

但它失敗:

的Runat必須有價值的服務器。

enter image description here

+0

使用JavaScript,並使其在客戶端上工作,並使用服務器只是爲了提供頁面。如果您真的想生成HTML服務器端,請使用asp.net文字控件,而不是response.write。 – frenchie

+0

你的意思是,我需要在aspx文件而不是主文件中編寫實際代碼? –

+0

我的意思是使用JavaScript和jQuery;把你的for循環中的代碼放在一個javascript函數中,並使用jQuery在document.ready上運行 – frenchie

回答

2

看看這個jsFiddle:

$(Start); 

function Start() { 

    var txtLeft, txtTop, theText, theHTML; 

    theText = "Hello there!"; 

    for (var i = 0; i < 30; i++) { 

     txtLeft = 300 + (100 * Math.sin(i)); 
     txtTop = 300 + (100 * Math.cos(i)); 

     theHTML = '<div style="position:absolute; left: ' + txtLeft + 'px; top:' + txtTop + 'px;">' + theText + '</div>'; 

     $('#Demo').append(theHTML); 
    } 
} 

基本上,有沒有需要服務器端編程,生成你想要的輸出;使用asp.net進行服務器工作。你可以做的是將這個腳本和jquery引用一起添加到script標記中的頁面中,然後就完成了。

+0

所以只需要一個線程等待javascript命令? –

+0

是的,您可以使用setTimeout對其進行修改,使其在一段時間後等待並回撥。 – frenchie