Vertical Text Scroller in Javascript

Well the task is to create a vertical text scroller.

It can be done using the javascript code.

Let me explain the process:

  • First of all lets make the form scrolling. So,In the html form do the following add the following attributes to the body tag onMouseover="scrollspeed=0" onMouseout="scrollspeed=current" OnLoad="NewsScrollStart();"
  • And the javascript functions used above are as follows:
    <script language="JavaScript" type="text/javascript"> 
    //<!-- HIDE CODE 
    
    var scrollspeed = "1" // SET SCROLLER SPEED 1 = SLOWEST 
    var speedjump = "30" // ADJUST SCROLL JUMPING = RANGE 20 TO 40 
    var startdelay = "2" // START SCROLLING DELAY IN SECONDS 
    var nextdelay = "0" // SECOND SCROLL DELAY IN SECONDS 0 = QUICKEST 
    var topspace = "2px" // TOP SPACING FIRST TIME SCROLLING 
    var frameheight = "200px" // IF YOU RESIZE THE WINDOW EDIT THIS HEIGHT TO MATCH 
    
    
    
    current = (scrollspeed) 
    
    
    function HeightData(){ 
    AreaHeight=dataobj.offsetHeight 
    if (AreaHeight==0){ 
    setTimeout("HeightData()",( startdelay * 1000 )) 
    } 
    else { 
    ScrollNewsDiv() 
    }} 
    
    function NewsScrollStart(){ 
    dataobj=document.all? document.all.NewsDiv : document.getElementById("NewsDiv") 
    dataobj.style.top=topspace 
    setTimeout("HeightData()",( startdelay * 1000 )) 
    } 
    
    function ScrollNewsDiv(){ 
    dataobj.style.top=parseInt(dataobj.style.top)-(scrollspeed) 
    if (parseInt(dataobj.style.top)<AreaHeight*(-1)) { 
    dataobj.style.top=frameheight 
    setTimeout("ScrollNewsDiv()",( nextdelay * 1000 )) 
    } 
    else { 
    setTimeout("ScrollNewsDiv()",speedjump) 
    }} 
    
    
    
    // END HIDE CODE --> 
    </script> 
    
    
    
    
    
  • Inside the body tag create a div element with id=”NewsDiv”
  • In the code behind add labels with text per line into this div as shown below
  • ///
    /// Handles the Load event of the Page control.
    ///
    /// The source of the event.
    /// The instance containing the event data.
    protected void Page_Load(object sender, EventArgs e)
    {
    GenerateAlert();
    }
    // Private Methods (1)

    ///
    /// this method extracts the alerts and show them in a label
    ///
    private void GenerateAlert()
    {
    XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load(Server.MapPath(“../XML Files/GlobalDisasters.xml”));
    XmlNodeList xmlndlst = xmldoc.GetElementsByTagName(“title”);

    for (int i = 0; i < xmlndlst.Count; i++)
    {
    lblAlert = new Label();
    string strTitle = xmlndlst[i].InnerText.ToString();
    lblAlert.Text = strTitle + “

    “;
    NewsDiv.Controls.Add(lblAlert);
    }
    }

    kick it on DotNetKicks.com

  • IP Address validation in C#

    dotnetlogo
    In this post, I have used Regular expression to validate if the IP address provided as string is valid IP Address or not.

    Usefull when we want user to input IP address in our application and we want to check if the IP address is corrct format or not.

    public bool IsValidIP(string addr)
    {
    //create our match pattern
    string strPattern = @”^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$”;
    //create our Regular Expression object
    Regex check = new Regex(strPattern);
    //boolean variable to hold the status
    bool valid = false;
    //check to make sure an ip address was provided
    if (addr == “”)
    {
    //no address provided so return false
    valid = false;
    }
    else
    {
    //address provided so use the IsMatch Method
    //of the Regular Expression object
    valid = check.IsMatch(addr, 0);
    }
    //return the results
    return valid;
    }

    kick it on DotNetKicks.com

    Parsing an XML file from RSS feed with namespaces in C#

    dotnetlogo
    The task is to parse a XML file retrieved from the RSS feed.
    Below is the sample partial XML file taken from a Leading Geographical alerts website’s RSS feeds.

    <?xml version="1.0" encoding="ISO-8859-1"?> 
    <rss version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/"> 
    <channel> 
    <pubDate>Fri, 4 Jan 2008 09:51 GMT+1</pubDate> 
    
    <item> 
    
    <title>Red alert: Tropical Cyclone SINLAKU-08.</title> 
    <description>Tropical Cyclone SINLAKU-08 .</description> 
    <pubDate>Tue, 16 Sep 2008 06:00 GMT+1</pubDate> 
    <geo:point> 
    <geo:lat>27</geo:lat> 
    <geo:long>124</geo:long> 
    </geo:point> 
    </item> 
    <item> 
    
    <title>Red alert: Tropical Cyclone IKE-08 .</title> 
    <description>Tropical Cyclone IKE-08 .</description> 
    <pubDate>Sun, 14 Sep 2008 09:00 GMT+1</pubDate> 
    <geo:point> 
    <geo:lat>36.400001526</geo:lat> 
    <geo:long>-92.5</geo:long> 
    </geo:point> 
    </item> 
    
    </channel> 
    </rss>
    
    

    As we can we there are two items(alerts) in the file one for Tropical Cyclone SINLAKU-08 and other for Tropical Cyclone IKE-08.

    Lets write the code in c# to extract title,latitude and longitude of both the alerts.

    First of all, lets load the XML data into the XMLDocument instance.

    //include namespace for working with xml files
    using System.Xml;
    public partial class GoogleMap : System.Web.UI.Page
    {
    //creating new instance of xml document
    XmlDocument xmlDoc = new XmlDocument();
    protected void Page_Load(object sender, EventArgs e)
    {
    xmlDoc.Load(Server.MapPath(“~/XML Files/sourceRssEDIS.xml”));
    //rest of the code described later will also be added here
    }
    }

    Now, introduce the namespaces used in the xml file to the xmlDoc with the XmlNamespaceManager class instance.

    XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDoc.NameTable);
    nsMgr.AddNamespace(“geo”, “http://www.w3.org/2003/01/geo/”);

    Select all the items in a array using GetElementsByTagName() method.

    XmlNodeList nodes = xmlDoc.GetElementsByTagName(“item”);

    Iterate for the elements inthe nodes array using for loop and select the latitude and longitude values using SelectNodes() method as shown below and then set the values of text of respective labels.

    for (int i = 0; i kick it on DotNetKicks.com