huseyin tugrul buyukisik
huseyin tugrul buyukisik

Reputation: 11910

Asp .Net client side dynamic text

Im learning Asp.Net, after writing a master page, I couldnt make it run on client (to actually see the animation). The thread waiting action is done on server before publishing the web page so animation is not dynamic. It shows only the final state of the page.

<!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>

I tried

runat="client" (near the "p" letter which is in brackets)

but it failed:

Runat must have value Server.

enter image description here

Upvotes: 2

Views: 83

Answers (1)

frenchie
frenchie

Reputation: 51927

Take a look at this 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);
    }
}

Basically, there's no need for server-side programming to generate the output you want; use asp.net for server work. What you can do is add this script to the page in a script tag along with the jquery reference and you're done.

Upvotes: 2

Related Questions