Mobile Content

Thursday, February 16, 2012

Moving label Text Up/Down continuously using Code in Asp.net

Animation using code


Here i am using updatepanel and timer to refresh page 

in .aspx


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="1000">
            </asp:Timer>


            <asp:Label ID="Lblanimation" runat="server" Text="Move Text"></asp:Label>


        </ContentTemplate>
  </asp:UpdatePanel>


in .cs page



if (ViewState["hit"] == null)
        {
            top = 1;
            top1 = 0;
           
        }
        else
        {
                     
           top = Convert.ToInt32(ViewState["hit"]);
           top1 = Convert.ToInt32(ViewState["hit1"]);
          
            if (top > 300 || top1>300)
            {
                top = (int)ViewState["hit"] - 1;
                top1 = (int)ViewState["hit1"] + 1;
                if (top == 1)
                {
                    top1 = 0;
                    left =Convert.ToInt32(ViewState["left"]) + 10;
                }
            }
            else
            {
                top = (int)ViewState["hit"] + 1;
                top1 = (int)ViewState["hit1"] + 1;
            }

        }
        lx.Attributes.Add("style", "top:"+top+"px;position:absolute;left:100px");
        ViewState["hit"] = top;
        ViewState["hit1"] = top1;
      

I have used viewstate to store the value generated when page get refresh

Label text move up and down continuously in every page refresh.
I have fixed the position up to 300 pixel. 




No comments:

Post a Comment