1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Using Date Passed to the Page

Discussion in 'C#' started by PhilSky, Feb 20, 2008.

  1. #1
    Although I think this is a fairly simple problem, I haven't been able to figure it out. I hope one you you experts out there can help me.

    My simple ASP page queries a SQL Server database and displays data for one day. If no date is passed to the page, I want it to use < yesterday >. Otherwise, it should use the value passed in. Whatever the date, it should be used in the query to the DB and also be displayed in the title such as:
    "Results For February 19, 2008"

    I have a little javascript that works when always using < yesterday > because the javascript itself figures out the correct date and formats it as desired. However it doesn't work in the more dynamic case.

    So, I've got two related problems.
    1. How do I figure out whether or not a date was passed to the page? (I assume I'll need to see if Request.Form.Count > 0, and then loop through the collection to find the value.)
    2. How do I then pass that value along to my javascript?

    The more detail that can be provided the better.

    THANKS!!
    PhilSky
     
    PhilSky, Feb 20, 2008 IP
  2. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi,

    do you mean having the date as an input box on the form or having the date passed as a querystring?
     
    Free Born John, Feb 20, 2008 IP
  3. HomeStart

    HomeStart Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Example of URL: http://foo.bar/page.asp?DATE=02/19/2008

    <%
    strDate = Request("DATE")
    If strDate = "" Then strDate = Now()-1
    %>
     
    HomeStart, Feb 20, 2008 IP
  4. PhilSky

    PhilSky Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To answer "Free Born John", the date is passed from an input box on the requesting form, not in the query string.

    To "HomeStart", you've solved one of my problems, but I still can't get the javascript to 'see' the variable. Here's the script itself:

    <SCRIPT Language= "JavaScript" >
    function displayTitle(strDate Text) {
    // Array list of months.
    var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

    var dataDate = new Date(strDate);
    dataDate.setDate(dataDate.getDate());

    rptTitle = "Daily High Activity Report As of " +
    months[dataDate.getMonth()] + " " +
    dataDate.getDate() + ", " +
    dataDate.getFullYear() ;

    // Print out the data.
    document.write(rptTitle);
    }
    </script>


    and then it is called as:

    <body>
    <hr noshade size="5" color="#B9B9FF">
    <p><b><font color="#800000"><center>
    <script type="text/javascript">
    displayTitle(HistDay);
    </script>
    </font></b></p>


    Perhaps I could change the script to just format and return the title string which is assigned to a variable and displayed later? But I suspect I'll have the same problem - that variable won't be visible when the page wants to display it. Further thoughts?
     
    PhilSky, Feb 21, 2008 IP