"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Sunday, December 26, 2010

Partially updating a webpage without refresh, using ajax Timer

Hi frienz,
wishing u all a merry Xmas. last day i was trying to hijack the countdown of rapid-share. My bad i think they where having some piece of script their but i didn't find anything :(. Then i done some googling and got some piece  that they are using some server side code. I hope they are using ajax without post-back they need it, i hope so
Demo

On aspx file

<form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                </Triggers>
                <ContentTemplate>
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                    </asp:Timer>
                    <center>
                        <h1>
                            <asp:Label ID="lblTimer" ForeColor="Brown" runat="server"></asp:Label>
                        </h1>
                    </center>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        <table><tr><td>Simply asp.net</td></tr></table>
    </div>
    </form>

on Aspx.cs file

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        lblTimer.Text = DateTime.Now.Hour.ToString() + " Hours " + DateTime.Now.Minute.ToString() + " Minutes " + DateTime.Now.Second.ToString() + " Seconds " + DateTime.Now.Millisecond.ToString()+" Milliseconds ";
    }

hope u Got what u looking


Have a nice day... 'N happy Coding :)

No comments: