Pages

Subscribe:

Tuesday, 28 January 2014

how to implement cookies on website open

 <div >
            <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="12000">
            </asp:Timer>
        </div>
        <div class="clr">
        </div>
        <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            <ContentTemplate>
                <div id="topfade" runat="server">
                    This site uses cookies. For more information on why we use cookies, please read
                    our <a href="#">privacy and cookie policy.</a> By continuing to view this website
                    <br>you are in agreement with its terms..&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span style="padding: 5px 10px 5px 10px; border: 1px solid #ffffff; background: #148ae4;">
                        <asp:LinkButton ID="cookies" runat="server" Text="Accept" OnClick="LinkButton_Clickcookies"
                            ForeColor="white" CausesValidation="false"></asp:LinkButton></span>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>


//code page

 protected void Timer1_Tick(object sender, EventArgs e)
    {
        topfade.Visible = false;
        Timer1.Enabled = false;
    }
    protected void LinkButton_Clickcookies(Object sender, EventArgs e)
    {
        HttpCookie myCookie = new HttpCookie("PetShow_cookies_policy");
        myCookie["Font"] = "Arial";
        myCookie["Color"] = "Blue";
        myCookie.Value = "The_PetShow14";
        myCookie.Expires = DateTime.Now.AddMonths(12);
        HttpContext.Current.Response.Cookies.Add(myCookie);
        topfade.Visible = false;
        topfade.InnerHtml = "";
    }

 protected void Page_Load(object sender, EventArgs e)
    {
 Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
        Response.Cache.SetNoStore();

 if (Request.Cookies["PetShow_cookies_policy"] != null)
        {
            topfade.Visible = false;
            Timer1.Enabled = false;
        }
        else
        {
            topfade.Visible = true;
        }
}

0 comments:

Post a Comment