Thursday, September 8, 2016

Using Image Map Control in ASP.NET

The ImageMap control in ASP.NET 2.0 and onward versions can be used to create an image that contains defined hot spot regions. When a user clicks a hot spot region, the control can either generate a post back to the server or navigate to a specified URL.
There are three kinds of hot spot regions defined in ImageMap control. 
  • ·         RectangleHotSpot
  • ·         CircleHotSpot
  • ·         PolygonHotSpot

The RectangleHotSpot defines rectangular hot spot regions. The CircleHotSpotdefines circle-shaped ones and the PolygonHotSpot is used for irregularly shaped hot spot area.

Let's have a look at one example:


Map.aspx

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

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table >
    <tr>
    <td colspan="4">
   
        <asp:ImageMap ID="india" runat="server"  ImageUrl ="~/Map.jpg" Height="500px"  Width="887px"  HotSpotMode="PostBack" OnClick="india_Click" BackColor="#C0C000" BorderColor="DarkSlateGray" ForeColor="Red">
        <asp:CircleHotSpot Radius="7" X="215" Y="125" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="bhuj" AlternateText="Bhuj" />
        <asp:CircleHotSpot Radius="7" X="525" Y="95" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="patan" />
        <asp:CircleHotSpot Radius="7" X="565" Y="45" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="ambaji" />
        <asp:CircleHotSpot Radius="7" X="525" Y="150" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="me" />
        <asp:CircleHotSpot Radius="7" X="625" Y="120" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="him" />
        <asp:CircleHotSpot Radius="7" X="495" Y="195" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="sure" />
        <asp:CircleHotSpot Radius="7" X="565" Y="195" HotSpotMode="PostBack" NavigateUrl="~/map.aspx" PostBackValue="ahd" />
    </asp:ImageMap>
    </td>
    <td colspan="2" style="width: 364px" align="left">
    <asp:Panel ID="p1" runat="server" Height="20px" Visible="false">
    <asp:Label ID="lbl1" Text="CITY:Bhuj STATE:Gujarat" runat ="server" Width="162px" Height="57px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
   
    </asp:Panel>
   
    <asp:Panel ID="p2" runat="server" Height="18px" Visible="false">
    <asp:Label ID="lbl2" Text="CITY:Patan STATE:Gujarat" runat ="server" Width="162px" Height="45px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
    </asp:Panel>
   
    <asp:Panel ID="p3" runat="server" Height="16px" Visible="false">
    <asp:Label ID="lbl3" Text="CITY:Ambaji STATE:Gujarat" runat ="server" Width="160px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
    </asp:Panel>
   
    <asp:Panel ID="p4" runat="server" Height="14px" Visible="false">
    <asp:Label ID="lbl4" Text="CITY:Mehsana STATE:Gujarat" runat ="server" Width="161px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
    </asp:Panel>
   
     <asp:Panel ID="p5" runat="server" Height="14px" Visible="false">
    <asp:Label ID="lbl5" Text="CITY:Himatnagar STATE:Gujarat" runat ="server" Width="161px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
    </asp:Panel>
   
     <asp:Panel ID="p6" runat="server" Height="14px" Visible="false">
    <asp:Label ID="lbl6" Text="CITY:Surendranagar STATE:Gujarat" runat ="server" Width="90px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
    </asp:Panel>
   
     <asp:Panel ID="p7" runat="server" Height="14px" Visible="false">
    <asp:Label ID="lbl7" Text="CITY:Ahemdabad STATE:Gujarat" runat ="server" Width="162px" BackColor="MediumVioletRed" Font-Bold="True" Font-Size="Larger" ForeColor="Blue"></asp:Label>
    </asp:Panel>
   
    </td>
    </tr>
    </table>
   
    </div>
           </form>
</body>
</html>

Map.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class map : System.Web.UI.Page
{
       
    protected void india_Click(object sender, ImageMapEventArgs e)
    {
        string aa = e.PostBackValue;
        if(aa=="bhuj")
        {
            p1.Visible =true ;
            p2.Visible = false;
            p3.Visible = false;
            p4.Visible = false;
            p5.Visible = false;
            p6.Visible = false;
            p7.Visible = false;
        }
        else if(aa=="patan")
        {
            p1.Visible =false ;
            p2.Visible =true ;
            p3.Visible = false;
            p4.Visible = false;
            p5.Visible = false;
            p6.Visible = false;
            p7.Visible = false;
        }

        else if (aa == "ambaji")
        {
            p1.Visible = false;
            p2.Visible = false;
            p3.Visible = true;
            p4.Visible = false;
            p5.Visible = false;
            p6.Visible = false;
            p7.Visible = false;

        }
        else if (aa == "him")
        {
            p1.Visible = false;
            p2.Visible = false;
            p3.Visible = false ;
            p5.Visible = true;
            p4.Visible = false;
            p6.Visible = false;
            p7.Visible = false;
           

        }

        else if (aa == "me")
        {
            p1.Visible = false;
            p2.Visible = false;
            p3.Visible = false ;
            p4.Visible = true;
            p5.Visible = false;
            p6.Visible = false;
            p7.Visible = false;
        }


        else if (aa == "sure")
        {
            p1.Visible = false;
            p2.Visible = false;
            p3.Visible = false;
            p5.Visible = false ;
            p4.Visible = false;
            p6.Visible = true;
            p7.Visible = false;
        }

        else if (aa == "ahd")
        {
            p1.Visible = false;
            p2.Visible = false;
            p3.Visible = false;
            p5.Visible = false ;
            p4.Visible = false;
            p7.Visible = true;
            p6.Visible = false;

        }

    }
}


Output:


Sunday, September 4, 2016

Understanding The Concept of HTML6


HTML6 is sixth revision of HTML with namespaces that has structure like XML. XML namespaces will help you use the same tag without conflicting it with any other tag.


For instance the one used in the XHTML DOCTYPE:



HTML6 will provide us the benefit to use tags that we want.


Just imagine using tag <logo></logo> for assigning a logo to your web page, or using tag <toolbar></toolbar> or using tag <wrapper> or a <container>  in place of <div> tag. It's better to use <wrapper> or <container> tag rather using <div> with multiple ids.


Example of HTML6:




Different new APIs are provided by HTML6.


Let's have a quick look.


HTML6 APIs:

Ø  <html:html>

This tag is equivalent to <html> tag.

<!DOCTYPE html>


<html:html>

  <!-- HTML Code goes here -->


</html:html>

Ø  <html:head>

This tag is equivalent to <head> tag.

<!DOCTYPE html>

<html:html>





  <html:head>

    <!-- Consists tags, like <html:title>,<html:meta> or <html:link> tag -->




  </html:head>

</html:html>


Ø  <html:title>

It will change the title of the HTML document and is similar to the <title> tag used in earlier HTML versions.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> My HTML6 Example</html:title>




  </html:head>

</html:html>


Ø  <html:meta>

This tag is little bit different from the <meta> tag used in the latest HTML version. Using this HTML6 tag you can use any sort of meta data.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> My HTML6 Example </html:title>




    <html:meta type="description" value=" Understanding The Concept of HTML6">

  </html:head>





</html:html>


Ø  <html:link>

This tag will help you link external documents and scripts (like CSS, JS files etc.) to the HTML document. It’s similar to <link> tag used in HTML.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> Understanding The Concept of HTML6
</html:title>




 <html:link src="javascript/mainfile.js" title="Script" type="text/javascript">

  </html:head>





</html:html>

Ø  <html:body>

This is just like the <body> tag that you’ve been using in the current HTML version.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> My HTML6 Example</html:title>




  </html:head>

  <html:body>





    <!-- Website content placed here -->

  </html:body>





</html:html>


Ø  <html:a>

This tag is similar to the <a> tag, and is used to represent a link to other web page. It takes only single ‘href’ attribute, which is used to redirect page.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> My HTML6 Example</html:title>




  </html:head>

  <html:body>





    <html:a href="http:/home">Home</html:a>

  </html:body>





</html:html>

Ø  <html:button>

This tag is equivalent to <button> tag or <input type="button"> used in the current and older HTML versions. This tag enables you to create a button to help a user perform some interaction to your web site.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> My HTML6 Example </html:title>




  </html:head>

  <html:body>





    <html:button>Click on This Button</html:button>

  </html:body>





</html:html>

Ø  <html:media>

This tag combines all the <media> tags like <img>,<audio>, <video>, <embed>, etc. The <html:media> tag you are  using will be executed by the browser based on the type attribute or it will make a guess on the basis of file extension or by the ‘MIME type’.


<!DOCTYPE html>

<html:html>





  <html:head>

    <html:title> My HTML6 Example </html:title>




  </html:head>

   <html:body>







 <html:media src="image/logo.jpg" type="image">

 <html:media src="videos/slider.mov">







  </html:body>
</html:html>

Types of  tags available in HTML6:


HTML6 will  have two types of tags similar to older version of HTML such as single tags and double tags. The single tags will not have any text content, and rather will only have attributes. They are also called self ended tags.


For example:


<html:meta type=" description " content=" My HTML6 Example " />
 

Double tags have opening and closing tag, as they have some text content.


For example:


<html:link href="./Home.html">Home</html:link>


HTML6 isn’t still finish here. But you can get an idea of what HTML6 will be offering.




Happy Coding...!!