0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cookie_test.aspx.cs" Inherits="cookie_test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/bootstrap-theme.min.css" rel="stylesheet" />
    <link href="css/layout.css" rel="stylesheet" />
    <link href="css/responsive.css" rel="stylesheet" />
    <link href="css/user_change.css" rel="stylesheet" />
      <link href="css/carousel.css" rel="stylesheet" />
    <link href="css/accordion.css" rel="stylesheet" />
    <link href="css/datepick.css" rel="stylesheet" />
    <link href="css/modalpopup.css" rel="stylesheet" />


 <script src="js/jquery-1.8.2.min.js"></script>

    <script src="js/jquery-1.9.1.js"></script>

    <script src="js/jquery.min.js"></script>
  <script src="js/jquery.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery-ui.min.js"></script>
    <script src="js/jquery.marquee.min.js"></script>
<script src="js/bootstrap.min.js"></script>  
<script src="js/respond.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.touchSwipe.min.js"></script>
<script src="js/responsiveslides.min.js"></script>
<script src="js/jquery-tinyNav.js"></script>
<script src="js/easyResponsiveTabs.js"></script>
<script src="js/jquery-validation.js"></script>
<script src="js/jquery.datepick.min.js"></script>
<script src="js/jquery.customSelect.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.simplemodal.js"></script>
<script src="js/jRating.jquery.js"></script>
<script src="js/jquery.screwdefaultbuttonsV2.min.js"></script>
<script src="js/global.js"></script>
<script src="js/jquery-hoverIntent.js"></script>
<script src="js/bootstrap-typeahead.js"></script>  
   <%-- <script src="js/modalpopup.js"></script>--%>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  <div id="loginModal">
            <h6>Sign Up For Our Newsletter</h6>

                <div id="loginForm" class="generalForm">

                <asp:TextBox ID="txtnewsletter" CssClass="loginName required" placeholder="Enter Your Email Address" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqtxtnewsletter1" runat="server" ErrorMessage="Field cannot be empty" ControlToValidate="txtnewsletter" ForeColor="Red" Display="Dynamic" ValidationGroup="newsletters"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="reqtxtnewsletter2" runat="server" ErrorMessage="Invalid Email ID" ControlToValidate="txtnewsletter" SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ForeColor="Red" Display="Dynamic" ValidationGroup="newsletters"></asp:RegularExpressionValidator>
                <div class="loginInner clearfix">
                     <asp:Button ID="btnSubmit" runat="server"  ValidationGroup="newsletters" CausesValidation="true"   Text="Submit" />

                </div>
                </div>

            <div class="loaderImg"></div>
        </div>
    </div>
    </form>
    <script>

            setTimeout(function () {
                $('#loginModal').modal('show');
            }, 5000);

        </script>
</body>
</html>


The above code is my front end code and the below is my backend code i want to call the popup from code behind how do i do it,
It pops up no matter if cookies  are set or no please help.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;

public partial class cookie_test : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
         check_cookies();
         create_cookies();


    }
    public void create_cookies()
    {
        HttpCookie mycookies = new HttpCookie("UserSettings");
        mycookies["User"] = "Visited";
        mycookies.Expires = DateTime.Now.AddDays(1);
        Response.Cookies.Add(mycookies);
    }
    public void check_cookies()
    {
        if (Request.Cookies["UserSettings"] != null)
        {
            Response.Write("Cookies not found");


        }
        else
            Response.Write("Cookies found");
        Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", "setTimeout();", true);
    }

}
2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by hericles
0

Your settimeout is firing everytime because it isn't wrapped in a function that needs to be called. It's just sitting there waiting to fire when that script block is reached. It is the same as putting alert('hi'); inside script tags. The alert will appear every time.
Create a function, with a name, that contains you settimeout and call that from your code behind.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.