AJAX time application

Last post 07-24-2008 4:26 AM by xCrystonSnow. 9 replies.

Sort Posts:

  • AJAX time application

    07-21-2008, 11:27 PM

    while passing the value of time from time1.aspx to testajax.aspx, the code below is being used.

    xmlHttp.onreadystatechange=function()
    {

     if
    (xmlHttp.readyState==4)
     {
      document.myForm.time.value=xmlHttp.responseText;
     }
    }
     xmlHttp.open(
    "GET","time1.aspx",true);
     xmlHttp.send(
    null);

    however, when the value of the time input(text) is being updated, the time appears like, -->

    11:32 AM<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head><title> Untitled Page</title></head><body>    <form name="form1" method="post" action="time1.aspx" id="form1"><div><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGTWUENbTgz7slxH7Q005QpbDmtjdQ==" /></div>    <div></div>    </form></body></html>

    how can i onli present the time without the html text of time1.aspx?

  • Re: AJAX time application

    07-22-2008, 6:48 AM
    • Loading...
    • Jeev
    • Joined on 11-24-2005, 7:49 AM
    • Posts 3,112

     Rather than using a page to send the time, use a web service and make a call to it.

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: AJAX time application

    07-23-2008, 10:53 PM

    Hi,

    You retrieved the data from .aspx file. But the .aspx file would generate the HTML code.

    Actually, after receiving the whole data from time1.aspx, you can use "substring" to get the specific characters.

    However, I'd like to suggest you use Generic Handler file(.ashx) instead of .aspx file to achieve it.

    Compared with .aspx file, the .ashx file won't create HTML code. So it is more efficient with this approach.

    You can check this link about ashx http://cs.jaxdug.com/blogs/dennisbottjer/archive/2005/06/20/730.aspx

    In this way, you can create time1.ashx file rather than time1.aspx.

    using System;
    using System.Web;
    
    public class Handler : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            
            context.Response.ContentType = "text/plain";
            context.Response.Write(DateTime.Now.ToString());
        }
    }
     
    Sincerely,
    Vince Xu
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: AJAX time application

    07-23-2008, 11:36 PM

    theres's stil an error. as this is the first time im touching on http handler .ashx file, there mite be many functions that i duno of. however, whenever i type anything and onKeyUp function, the time will regenerated. therefore on the .aspx file there is a response.expire=-1; to set the page to nt expire forever to allow me to retrieve the time anitime. as this web sample is an AJAX sample, i am unsure if .ashx is usable compared to .aspx. as i tried to apply .ashx, there are many errors on handlers which is too much for a newbie like me. isit possible to solve the html codes compared to using .ashx? i am able to publish the time but the html codes juz kept appearing with the time..

  • Re: AJAX time application

    07-24-2008, 12:39 AM
    Answer

    Hi,

    Did you still set response.expire=-1 in .ashx file? Actually, it needn't. It will ouput the newest DateTime on server with the below code.

    In ashx file, we can use context.Response.Write rather than just Response.Write.

    time1.ashx:

    <%@ WebHandler Language="C#" Class="Handler" %>

    using System;
    using System.Web;

    public class Handler : IHttpHandler {
       
        public void ProcessRequest (HttpContext context) {
           
            context.Response.ContentType = "text/plain";
            context.Response.Write(DateTime.Now.ToString());
        }

    }

    And you can use xmlhttprequest to retrieve the data.

     

    vvar XMLHttpFactories = [
     function () {return new XMLHttpRequest()},
     function () {return new ActiveXObject("Msxml2.XMLHTTP")},
     function () {return new ActiveXObject("Msxml3.XMLHTTP")},
     function () {return new ActiveXObject("Microsoft.XMLHTTP")}
    ];
    
    function createXMLHTTPObject() {
     var xmlhttp = false;
     for (var i=0;i<XMLHttpFactories.length;i++) {
      try {
       xmlhttp = XMLHttpFactories[i]();
      }
      catch (e) {
       continue;
      }
      break;
     }
     return xmlhttp;
    }
    
    function GetTime()
    {
    
        var url="time1.ashx";
        var xmlhttp = createXMLHTTPObject();;
        xmlhttp.open("GET", url,true);
        xmlhttp.onreadystatechange=function() 
        {
            if (xmlhttp.readyState==4) 
            {
                var responsetext=xmlhttp.responseText;
        
                document.getElementById('timetext').value=responsetext;
            }
        }
        xmlhttp.send(null);
    
    }
    
    
    <input id="timetext" type="text" />
     
    Sincerely,
    Vince Xu
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: AJAX time application

    07-24-2008, 2:14 AM

    Hi,

    thanks for helping me with the previous tutorial. I am currently working out on how to create a calendar that displays information for the day retreived from database when the mouse's cursor rollover on the date on the calendar. I intend to use tooltip feature to display the information retreived. but i do not know how to apply it on the calendar. Any ideas on how to work on the calendar?

  • Re: AJAX time application

    07-24-2008, 2:42 AM

    Hi,

    Based on my understanding, you want to display the information for days from database on Calendar control.

    You can create mouse over tooltip for days in Calendar. If mouse cursor is over a specific day, the information on that day appears.

    To display the tooltips, you can download ’wz_tooltip.zip‘ from the following link first: http://www.walterzorn.com/tooltip/tooltip_e.htm.

    After downloading the tool, you can add the JavaScript file into the ASPX file to reference it: 

    <script type="text/javascript" src="../js/wz_tooltip.js"></script>.

    Then add a mouseover event on the specific date: 
        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date.Day == 18)
            {            
                string s = "this day is 18";//select from database
                e.Cell.Controls.Add(new LiteralControl("<a href='#' onmouseover=\"Tip('"+s+"')\">*</a>"));
            }
        }

     

    Sincerely,
    Vince Xu
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: AJAX time application

    07-24-2008, 3:10 AM

    thanks it really helps. i hope to further improve.. can i use the e.SelectURL to display the tooltip?

    is there any way to get the control of the date and use it to display the tooltip without other literalcontrol? from my application, if my cursor does nt go over the asterisk(*), i am unable to display the tooltip. furthermore, it displays 2 tooltip which is the string s="it is 18", and "July 18" by default.

  • Re: AJAX time application

    07-24-2008, 3:49 AM
    Answer

    Hi,

    1.Character "*" can mark the specific day and illuminate that there is some information for the day.

    You can add the tooltip onto the cell directly. Please use the below code

                e.Cell.Attributes["onmouseover"] = "Tip('" + s + "')";

    instead of

                e.Cell.Controls.Add(new LiteralControl("<a href='#' onmouseover=\"Tip('"+s+"')\">*</a>"));

    Then when you move the mouse cursor onto the specific day, the tooltip appears.

    2.You can present the tooltip by filtering the days in DayRender event.

    For example, you can select the related information for days from database with e.Day.Date.
     

    3.e.SelectURL is readonly, it's not helpful to present tooltip.

     

    Sincerely,
    Vince Xu
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: AJAX time application

    07-24-2008, 4:26 AM

    thanks. i've solved the problem for the calendar, you've been of great help. Big Smile

Page 1 of 1 (10 items)
Microsoft Communities
Page view counter