Monday, April 14, 2014

Position in CSS



Different Types of Position in CSS:


  • Static. This is the default for every single page element. Different elements don't have different default values for positioning, they all start out as static. Static doesn't mean much, it just means that the element will flow into the page as it normally would. The only reason you would ever set an element to position: static is to forcefully-remove some positioning that got applied to an element outside of your control. This is fairly rare, as positioning doesn't cascade.
     
  • Relative. This type of positioning is probably the most confusing and misused. What it really means is "relative to itself". If you set position: relative; on an element but no other positioning attributes (top, left, bottom or right), it will no effect on it's positioning at all, it will be exactly as it would be if you left it as position: static; But if you DO give it some other positioning attribute, say, top: 10px;, it will shift it's position 10 pixels DOWN from where it would NORMALLY be. I'm sure you can imagine, the ability to shift an element around based on it's regular position is pretty useful. I find myself using this to line up form elements many times that have a tendency to not want to line up how I want them to.
    There are two other things that happen when you set position: relative; on an element that you should be aware of. One is that it introduces the ability to use z-index on that element, which doesn't really work with statically positioned elements. Even if you don't set a z-index value, this element will now appear on top of any other statically positioned element. You can't fight it by setting a higher z-index value on a statically positioned element. The other thing that happens is it limits the scope of absolutely positioned child elements. Any element that is a child of the relatively positioned element can be absolutely positioned within that block. This brings up some powerful opportunities which I talk about here.

  • Absolute. This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. Remember that these values will be relative to the next parent element with relative (or absolute) positioning. If there is no such parent, it will default all the way back up to the <html> element itself meaning it will be placed relatively to the page itself.
    The trade-off, and most important thing to remember, about absolute positioning is that these elements are removed from the flow of elements on the page. An element with this type of positioning is not affected by other elements and it doesn't affect other elements. This is a serious thing to consider every time you use absolute positioning. It's overuse or improper use can limit the flexibility of your site.

  • Fixed. This type of positioning is fairly rare but certainly has its uses. A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn't change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled, creating an effect a bit like the old school "frames" days. Take a look at this site (update: dead link, sorry), where the left sidebar is fixed. This site is a perfect example for since it exhibits both good and bad traits of fixed positioning. The good is that it keeps the navigation present at all times on the page and it creates and interested effect on the page. The bad is that there are some usability concerns. On my smallish laptop, the content in the sidebar is cut off and there is no way from me to scroll down to see the rest of that content. Also if I scroll all the way down to the footer, it overlaps the footer content not allowing me to see all of that. Cool effect, can be useful, but needs to be thoroughly tested.

Tuesday, March 25, 2014

Access Property in Jquery/Javascript

Public Property Declared in .cs file

 Public Property PId() As Integer
            Get
                Return _PId
            End Get
            Set(ByVal value As Integer)
                _PId= value
            End Set
        End Property


 Public Property LocationID () As Integer
            Get
                Return _LocationID
            End Get
            Set(ByVal value As Integer)
                _LocationID = value
            End Set
        End Property

Note:-To access property it should be declared as Public

Access property in Jquery/Javascript:

 var PatientID = eval('<%= PId%>');
 var LocationID = eval('<%=LocationID %>');

Monday, March 3, 2014

Parse Json Data In VB.Net or C#

Complex Json Data:

[
    {
        "input_index": 0,
        "candidate_index": 0,
        "delivery_line_1": "1600 Amphitheatre Pkwy",
        "last_line": "Mountain View CA 94043-1351",
        "delivery_point_barcode": "940431351000",
        "components": {
            "primary_number": "1600",
            "street_name": "Amphitheatre",
            "street_suffix": "Pkwy",
            "city_name": "Mountain View",
            "state_abbreviation": "CA",
            "zipcode": "94043",
            "plus4_code": "1351",
            "delivery_point": "00",
            "delivery_point_check_digit": "0"
        },
        "metadata": {
            "record_type": "S",
            "zip_type": "Standard",
            "county_fips": "06085",
            "county_name": "Santa Clara",
            "carrier_route": "C909",
            "congressional_district": "18",
            "rdi": "Commercial",
            "elot_sequence": "0089",
            "elot_sort": "A",
            "latitude": 37.42202,
            "longitude": -122.08433,
            "precision": "Zip9",
            "time_zone": "Pacific",
            "utc_offset": -8.0,
            "dst": true
        },
        "analysis": {
            "dpv_match_code": "Y",
            "dpv_footnotes": "AABB",
            "dpv_cmra": "N",
            "dpv_vacant": "N",
            "active": "Y",
            "footnotes": "N#"
        }
    }
]
 

Add these references

1) ADD these references

Imports System.ServiceModel.Web 
Imports System.Runtime.Serialization

Create the classes to support the json data

1)Create Classes to support json
2) Note the attributes used for class <DataContract()> and datatype <DataMember()>
3)The name of the property should be same as that in the json data

 

<DataContract()>   //class attribute
    Public Class JsonData

        Private _input_index As String
        <DataMember()>                     //datatype attribute
        Public Property input_index As String  //name of  property same as Json
            Get
                Return _input_index
            End Get
            Set(ByVal value As String)
                _input_index = value
            End Set
        End Property
        Private _candidate_index As String
        <DataMember()>
        Public Property candidate_index As String
            Get
                Return _candidate_index
            End Get
            Set(ByVal value As String)
                _candidate_index = value
            End Set
        End Property
        Private _delivery_line_1 As String
        <DataMember()>
        Public Property delivery_line_1 As String
            Get
                Return _delivery_line_1
            End Get
            Set(ByVal value As String)
                _delivery_line_1 = value
            End Set
        End Property
        Private _last_line As String
        <DataMember()>
        Public Property last_line As String
            Get
                Return _last_line
            End Get
            Set(ByVal value As String)
                _last_line = value
            End Set
        End Property
        Private _delivery_point_barcode As String
        <DataMember()>
        Public Property delivery_point_barcode As String
            Get
                Return _delivery_point_barcode
            End Get
            Set(ByVal value As String)
                _delivery_point_barcode = value
            End Set
        End Property
        Private _Componentlist As components    //the class of this list is down 
        <DataMember()>
        Public Property components As components    // note here: name is same same as in json 
            Get
                Return _Componentlist
            End Get
            Set(ByVal value As components)
                _Componentlist = value
            End Set
        End Property
        Private _metadatalist As metadata  //the class of this list is down
        <DataMember()>
        Public Property metadata As metadata
            Get
                Return _metadatalist
            End Get
            Set(ByVal value As metadata)
                _metadatalist = value
            End Set
        End Property
        Private _anslysislist As analysis  //the class of this list is down
        <DataMember()>
        Public Property analysis As analysis
            Get
                Return _anslysislist
            End Get
            Set(ByVal value As analysis)
                _anslysislist = value
            End Set
        End Property
    End Class

    <DataContract()>
    Public Class components

        Private _primarynumber As Integer
        <DataMember()>
        Public Property primary_number As String
            Get
                Return _primarynumber
            End Get
            Set(ByVal value As String)
                _primarynumber = value
            End Set
        End Property
        Private _streetname As String
        <DataMember()>
        Public Property street_name As String
            Get
                Return _streetname
            End Get
            Set(ByVal value As String)
                _streetname = value
            End Set
        End Property
        Private _streetsufix As String
        <DataMember()>
        Public Property street_suffix As String
            Get
                Return _streetsufix
            End Get
            Set(ByVal value As String)
                _streetsufix = value
            End Set
        End Property

        Private _city_name As String
        <DataMember()>
        Public Property city_name As String
            Get
                Return _city_name
            End Get
            Set(ByVal value As String)
                _city_name = value
            End Set
        End Property
        Private _state_abbreviation As String
        <DataMember()>
        Public Property state_abbreviation As String
            Get
                Return _state_abbreviation
            End Get
            Set(ByVal value As String)
                _state_abbreviation = value
            End Set
        End Property
        Private _zipcode As String
        <DataMember()>
        Public Property zipcode As String
            Get
                Return _zipcode
            End Get
            Set(ByVal value As String)
                _zipcode = value
            End Set
        End Property
        Private _plus4_code As Integer
        <DataMember()>
        Public Property plus4_code As String
            Get
                Return _plus4_code
            End Get
            Set(ByVal value As String)
                _plus4_code = value
            End Set
        End Property
        Private _delivery_point As Integer
        <DataMember()>
        Public Property delivery_point As String
            Get
                Return _delivery_point
            End Get
            Set(ByVal value As String)
                _delivery_point = value
            End Set
        End Property
        Private _delivery_point_check_digit As Integer
        <DataMember()>
        Public Property delivery_point_check_digit As String
            Get
                Return _delivery_point_check_digit
            End Get
            Set(ByVal value As String)
                _delivery_point_check_digit = value
            End Set
        End Property
    End Class

    <DataContract()>
    Public Class metadata
        Private _record_type As String
        <DataMember()>
        Public Property record_type As String
            Get
                Return _record_type
            End Get
            Set(ByVal value As String)
                _record_type = value
            End Set
        End Property


        Private _zip_type As String
        <DataMember()>
        Public Property zip_type As String
            Get
                Return _zip_type
            End Get
            Set(ByVal value As String)
                _zip_type = value
            End Set
        End Property
        Private _county_fips As String
        <DataMember()>
        Public Property county_fips As String
            Get
                Return _county_fips
            End Get
            Set(ByVal value As String)
                _county_fips = value
            End Set
        End Property
        Private _county_name As String
        <DataMember()>
        Public Property county_name As String
            Get
                Return _county_name
            End Get
            Set(ByVal value As String)
                _county_name = value
            End Set
        End Property
        Private _carrier_route As String
        <DataMember()>
        Public Property carrier_route As String
            Get
                Return _carrier_route
            End Get
            Set(ByVal value As String)
                _carrier_route = value
            End Set
        End Property
        Private _congressional_district As String
        <DataMember()>
        Public Property congressional_district As String
            Get
                Return _congressional_district
            End Get
            Set(ByVal value As String)
                _congressional_district = value
            End Set
        End Property
        Private _rdi As String
        <DataMember()>
        Public Property rdi As String
            Get
                Return _rdi
            End Get
            Set(ByVal value As String)
                _rdi = value
            End Set
        End Property
        Private _elot_sequence As String
        <DataMember()>
        Public Property elot_sequence As String
            Get
                Return _elot_sequence
            End Get
            Set(ByVal value As String)
                _elot_sequence = value
            End Set
        End Property
        Private _elot_sort As String
        <DataMember()>
        Public Property elot_sort As String
            Get
                Return _elot_sort
            End Get
            Set(ByVal value As String)
                _elot_sort = value
            End Set
        End Property

        Private _latitude As String
        <DataMember()>
        Public Property latitude As String
            Get
                Return _latitude
            End Get
            Set(ByVal value As String)
                _latitude = value
            End Set
        End Property
        Private _longitude As String
        <DataMember()>
        Public Property longitude As String
            Get
                Return _longitude
            End Get
            Set(ByVal value As String)
                _longitude = value
            End Set
        End Property
        Private _precision As String
        <DataMember()>
        Public Property precision As String
            Get
                Return _precision
            End Get
            Set(ByVal value As String)
                _precision = value
            End Set
        End Property
        Private _time_zone As String
        <DataMember()>
        Public Property time_zone As String
            Get
                Return _time_zone
            End Get
            Set(ByVal value As String)
                _time_zone = value
            End Set
        End Property
        Private _utc_offset As String
        <DataMember()>
        Public Property utc_offset As String
            Get
                Return _utc_offset
            End Get
            Set(ByVal value As String)
                _utc_offset = value
            End Set
        End Property
        Private _dst As String
        <DataMember()>
        Public Property dst As String
            Get
                Return _dst
            End Get
            Set(ByVal value As String)
                _dst = value
            End Set
        End Property
    End Class

    <DataContract()>
    Public Class analysis
        Private _dpv_match_code As String
        <DataMember()>
        Public Property dpv_match_code As String
            Get
                Return _dpv_match_code
            End Get
            Set(ByVal value As String)
                _dpv_match_code = value
            End Set
        End Property
        Private _dpv_footnotes As String
        <DataMember()>
        Public Property dpv_footnotes As String
            Get
                Return _dpv_footnotes
            End Get
            Set(ByVal value As String)
                _dpv_footnotes = value
            End Set
        End Property
        Private _dpv_cmra As String
        <DataMember()>
        Public Property dpv_cmra As String
            Get
                Return _dpv_cmra
            End Get
            Set(ByVal value As String)
                _dpv_cmra = value
            End Set
        End Property
        Private _dpv_vacant As String
        <DataMember()>
        Public Property dpv_vacant As String
            Get
                Return _dpv_vacant
            End Get
            Set(ByVal value As String)
                _dpv_vacant = value
            End Set
        End Property
        Private _active As String
        <DataMember()>
        Public Property active As String
            Get
                Return _active
            End Get
            Set(ByVal value As String)
                _active = value
            End Set
        End Property
        Private _footnotes As String
        <DataMember()>
        Public Property footnotes As String
            Get
                Return _footnotes
            End Get
            Set(ByVal value As String)
                _footnotes = value
            End Set
        End Property
 


Get the values from the json String:

Dim output As String
output = objUSPSAPI.FormatJson(wsClient.DownloadString(inputUrl))  ' download json string from external source
Dim JsonDataobj = New List(Of JsonData)
Dim ser = New DataContractJsonSerializer(GetType(List(Of JsonData)))
Dim stream = New MemoryStream(Encoding.UTF8.GetBytes(output))
JsonDataobj = TryCast(ser.ReadObject(stream), List(Of JsonData))
If JsonDataobj IsNot Nothing AndAlso JsonDataobj.Count > 0 Then
    Dim Uspsdata As New DataTable
    Uspsdata.Columns.Add("primary_number", GetType(System.String))
    Uspsdata.Columns.Add("street_name", GetType(System.String))
    Uspsdata.Columns.Add("street_suffix", GetType(System.String))
    Uspsdata.Columns.Add("city_name", GetType(System.String))
    Uspsdata.Columns.Add("state_abbreviation", GetType(System.String))
    Uspsdata.Columns.Add("zipcode", GetType(System.String))
    Uspsdata.Columns.Add("plus4_code", GetType(System.String))
    Uspsdata.Columns.Add("delivery_point", GetType(System.String))
    Uspsdata.Columns.Add("delivery_point_check_digit", GetType(System.String))
    Dim dr As DataRow
    For Each objaddress As JsonData In JsonDataobj
        If Not objaddress.components Is Nothing Then
            dr = Uspsdata.NewRow
            dr("primary_number") = objaddress.components.primary_number.ToString()
            dr("street_name") = objaddress.components.street_name.ToString()
            dr("street_suffix") = objaddress.components.street_suffix.ToString()
            dr("city_name") = objaddress.components.city_name.ToString()
            dr("state_abbreviation") = objaddress.components.state_abbreviation.ToString()
            dr("zipcode") = objaddress.components.zipcode.ToString()
            dr("plus4_code") = objaddress.components.plus4_code.ToString()
            dr("delivery_point") = objaddress.components.delivery_point.ToString()
            dr("delivery_point_check_digit") = objaddress.components.delivery_point_check_digit.ToString()
            Uspsdata.Rows.Add(dr)
        End If
    Next