Tuesday, November 27, 2012

Deserialize and serialize json in .net

public static T Deserialise<T>(string json) { T obj = Activator.CreateInstance<T>(); using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); obj = (T)serializer.ReadObject(ms); // <== Your missing line return obj; } }

public static string Serialize<T>(T obj) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, obj); return Encoding.Default.GetString(ms.ToArray()); } }

//define object t
[DataContract]
    public class SearchResult
    {

//text means the attribute in json string
        [DataMember(Name = "text", Order = 0)]
        public string Text { get; set; }

        [DataMember(Name = "to_user_id", Order = 1)]
        public int? ToUserId { get; set; }
       
        [DataMember(Name = "from_user", Order = 2)]
        public string FromUser { get; set; }

        [DataMember(Name = "id_str", Order = 3)]
        public long Id { get; set; }

        [DataMember(Name = "from_user_id", Order = 4)]
        public long? FromUserId { get; set; }

        [DataMember(Name = "iso_language_code", Order = 5)]
        public string IsoLanguageCode { get; set; }

        [DataMember(Name = "profile_image_url", Order = 6)]
        public string ProfileImageUrl { get; set; }

        [DataMember(Name = "created_at", Order = 7)]
        public string CreatedAt { get; set; }
    }

Friday, November 2, 2012

create an infinite scroller

<%
@ Control Language="C#" AutoEventWireup="true" CodeBehind="AdvertPlus.ascx.cs"

Inherits="lokalmatador.MeinOrtControls.AdvertPlus" %>
<div class="full meinOrtBox advertPlus">

 

<div class="contentHeader">


<div class="boxheader">

Anzeigen aus Ubstadt-Weiher und Umgebung
</div>


</div>


<div class="contentBody">


<div class="adArrows">


<div class="leftArrow">


</div>


</div>


<div class="advertPlusSliderWrapper">


<ul class="adSlider">


<asp:Repeater ID="RepeaterAdvertPlus" runat="server"


onitemdatabound="RepeaterAdvertPlus_ItemDataBound" >


<ItemTemplate>


<li class="adSlide">


<div class="adimg">


<asp:Image ID="advertPlusImg" runat="server" alt="" width="100" height="67" /></div>


<div runat="server" id="adCityName" class="adCategory"></div>


<div runat="server" id="adCategory" class="adCategory"></div>


<div runat="server" id="adCompany" class="adCompany"></div>


</li>


</ItemTemplate>


</asp:Repeater>


</ul>


</div>


<div class="adArrows">


<div class="rightArrow">


</div>


</div>


<div class="adCategoryList">


<ul>


<li><a href="#"><strong>> </strong>Stellen</a></li>


<li><a href="#"><strong>> </strong>Immobilien</a></li>


<li><a href="#"><strong>> </strong>Auto</a></li>


<li><a href="#"><strong>> </strong>Gastronomie</a></li>


<li><a href="#"><strong>> </strong>Gesundheit</a></li>


<li><a href="#"><strong>> </strong>Trauer</a></li>


</ul>


</div>


</div>

</

div>


if

($('.adSlider li').length > 5) {

$(
'.adSlider li:first').before($('.adSlider li:last'));

cycle =
function (direction, distance, durationTime) {


if (direction == "left") {


//make the sliding effect using jquery's anumate function '

$(
'.adSlider:not(:animated)').animate({ 'left': 0 }, durationTime, function () {


//get the first last item and put it before the first list item (that's how the infinite effects is made) '

$(
'.adSlider li:first').before($('.adSlider li:last'));


//and get the left indent to the default -120px

$(
'.adSlider').css({ 'left': '-120px' });

});

}


else if (direction == "right") {

$(
'.adSlider:not(:animated)').animate({ 'left': -distance }, durationTime, function () {


//get the first list item and put it after the last list item (that's how the infinite effects is made) '

$(
'.adSlider li:last').after($('.adSlider li:first'));


//and get the left indent to the default -120px

$(
'.adSlider').css({ 'left': '0px' });

});

}

};


var timer = self.setInterval(function () { cycle('right', 120, 500); }, 2000);

$(
".adArrows").children('.leftArrow').click(function () {

cycle(
'left', 120, 500);

});

$(

".adArrows").children('.rightArrow').click(function () {

cycle(
'right', 120, 500);

});

$(

'.adSlider').mouseenter(function () {

self.clearInterval(timer);

}).mouseleave(

function () {

timer = self.setInterval(
function () { cycle('right', 120, 500); }, 2000);

});

}











/* CSS Document */



body

{


font-family:Arial, Helvetica, sans-serif;

}


/*-------PopUp Styles-------*/



.popUp



{


z-index:99;


width:460px;




padding:40px 10px 10px 10px;


background-repeat:repeat-x;


background-color:#868686;


border:solid 1px #9c9c9c;




margin-bottom:10px;


font-size:12px;


color:#4d4d4d;


background-image:url(/storage/MyCityInfoControl/div-border.jpg);

}

 


.innerPopUp

{


padding:10px;


background-color:white;


margin-left:auto;


margin-right:auto;


max-height:480px;




position:relative;




border:solid 1px #b0b0b0;


overflow-y:auto;

}


.popUp

.closeButton{


position:absolute;


background-image:url('/storage/MyCityInfoControl/div-close.png');


background-repeat:no-repeat;


cursor:pointer;


position:absolute;


width:26px;


height:26px;


position:absolute;


right: 10px;


top: 7px;

}


.headerContentPopUp

.boxRightArrow{


background-image:url('/storage/MyCityInfoControl/div-arrow.png');


position:absolute;


width:9px;


height:26px;


right:-9px;


top:0;

}


.popUpHeader

{


position: absolute;

width

: 424px;

height

: 30px;

font-size

: 14px;

font-weight

: bold;

color

: #717171;

left

: 7px;

top

: 5px;

padding

: 9px;

z-index

: 88;

}


.KUR_div



{


position:absolute;


left:244px;


display:none;

}

 

 


.GEM_div



{


position:absolute;


display:none;


top:30px;


left:244px;

}

 


.WIC_div



{


position:absolute;


display:none;


top:60px;


left:244px;

}

 

 


/* DropDownList cities*/



.SelectedCity

{


cursor:pointer;


float:left;


left:20px;


position:relative;


top:5px;


width: 355px;


height: 31px;

}


.SelectedCity_leftBracket

{


position:relative;


float:left;


background-image:url('/storage/MyCityInfoControl/DropDown.png');


background-repeat:no-repeat;


background-position:0px -1px;


height:33px;


width:7px;




z-index:70;

}


.SelectedCity_upLine

{


position:fixed;


border:none;


height:1px;


background-color:#bababa;


left:186px;


top:6.5px;


width:355px;


z-index:80;

}

 


.SelectedCity_middle



{


position:relative;


float:left;


background-image:url('/storage/MyCityInfoControl/DropDown.png');


background-position:0px -70px;


height:33px;


width:325px;


background-repeat:repeat-x;



}


.SelectedCity_display



{


padding-left:8px;


padding-top:4px;


width: 300px;


height: 22px;


color: #8f8f8f;


font-size: 16px;


top:5px;


left:1px;


border:none;


position:absolute;


background-color:transparent;


outline:none;

}


.SelectedCity_arrow

{


position:absolute;


background-image:url('/storage/MyCityInfoControl/DropDown.png');


background-repeat:no-repeat;


background-position:0px -106px;


height:13px;


width:15px;


top: 13px;


right: 5px;

}


.SelectedCity_downLine

{


position:fixed;


border:none;


background-color:#bababa;


height:1px;


left:186px;


top:35px;


width:355px;

}


.SelectedCity_rightBracket

{


position:relative;


float:left;


background-image:url('/storage/MyCityInfoControl/DropDown.png');


background-repeat:no-repeat;


background-position:-3px -36.2px;


height:33px;


width:15px;



}


.Cities

{


z-index:98;


position: absolute;


left:175px;


top:32px;


display:none;


width: 355px;


height: 235px;

}


.Cities_arrow

{


position:absolute;


background-image:url('/storage/MyCityInfoControl/DropDown.png');


background-repeat:no-repeat;


background-position:0px -119px;


height:15px;


width:15px;


right: 42px;


top: 7px;

}


.Cities_ul



{


border:solid 1px #bababa;


background-color:white;


font-size:13px;


width: 333px;


overflow:auto;


height: 244px;


list-style:none;


padding-left:0px;


margin-top:15px;



}


.Cities_li



{


font-size:13px;


color:#bababa;


cursor:pointer;


padding:8px 0 8px 8px;

}


.Cities_li_highlight

{


background-color:#efefef;

}

 

 

 

 


.contentWrapper

{


position:relative;


float:left;


width:900px;

}


.pageHeader

{


position:relative;


float:left;


width:880px;


margin-bottom:3px;

}


.pageTitle

{


position:relative;


float:left;


font-size:36px;


color:#8f8f8f;


font-weight:bold;


margin-left:10px;

}


.weatherWidget

{


position:relative;


float:right;


padding-top:8px;



}


/*-------Mein Ort Header-------*/



.meinOrtHeader

{


position:relative;


float:left;


width:878px;


height:245px;


margin-right:10px;


margin-left:10px;


margin-bottom:20px;


border:solid 1px #656565;

}


.headerImgSliderWrapper

{


position:relative;


float:left;


width:725px;

}


.ortHeaderLinks

{


background-image:url(/storage/MyCityInfoControl/headerlinkbg.jpg);


background-repeat:repeat-x;


width:152px;


height:245px;


position:relative;


float:left;


border-left:solid 1px #222222;


font-size:10px;


color:#4d4d4d;


font-variant:small-caps;

}


.ortHeaderLinks

a{


color:#4d4d4d!important;

}


.ortHeaderLinks ul{


list-style:none;


padding:0;


margin:0;

}


.ortHeaderLinks ul li{


padding:9px 0px 10px 10px;


display:block;


height:11px;


border-bottom:solid 1px #95979b;


cursor:pointer;

}


ul

li.last{


border-bottom:none!important;

}


.ortHeaderImage

{


position:relative;


float:left;


width:725px;


height:190px;


overflow:hidden;

}


.ortHeaderSlider

{


position:relative;


float:left;


width:720px;


height:49px;


overflow:hidden;


background-color:#686868;


border-top:solid 1px #222222;


padding-top:5px;


padding-left:5px;

}


.topArrows

{


position:relative;


float:left;


margin-top:1px;

}




.topArrows .leftArrow{


background-image:url(/storage/MyCityInfoControl/arrows.png);


background-position:-3px -40px;


cursor:pointer;


width: 37px;


height:28px;


position:relative;


margin-right:4px;


top:8px;

}






.topArrows .rightArrow{


background-image:url(/storage/MyCityInfoControl/arrows.png);


background-position:-48px -40px;


cursor:pointer;


width: 37px;


height:28px;


position:relative;


top:8px;

}




.topSliderWrapper{


position:relative;


float:left;


width:292px;

}




.topSlider{


list-style:none;


margin:0;


padding:0;

}




.topSlider li{


position:relative;


float:left;


margin:0 3px;

}


/*.topSlide img{

border: solid 3px #ffffff;

}*/




.img{


border: solid 3px #ffffff;


cursor:pointer;

}


.imgActive{


border: solid 3px ActiveBorder;


cursor:pointer;



}




.imgClicked{


border: solid 3px HighLight;


cursor:pointer;



}






/*-------end Mein Ort Header-------*/



/*-------Box Stucture-------*/



.meinOrtBox

{


background-color:#f6f6f6;


border-top:3px solid #585858;


position:relative;


float:left;


margin-right:10px;


margin-left:10px;


line-height:14px;

}


.contentHeader

{


position:relative;


float:left;


width:100%;


height:23px;


background-color:#e5e5e5;

}


.medium

{


position:relative;


float:left;


width:580px;


height:245px;


margin-right:10px;


margin-left:10px;


margin-bottom:20px;

}


.small

{


position:relative;


float:left;


width:280px;


height:245px;


margin-right:10px;


margin-left:10px;


margin-bottom:20px;

}


.facebook

{


background-color:transparent!important;


border-top:none!important;

}


.full

{


position:relative;


float:left;


width:880px;


height:245px;


margin-right:10px;


margin-left:10px;


margin-bottom:20px;

}


.half

{


position:relative;


float:left;


width:430px;


height:245px;


margin-right:10px;


margin-left:10px;


margin-bottom:20px;

}


.noBG

{


background-color:transparent!important;

}


.boxheader

{


padding:5px;


font-size:12px;


position:relative;


float:left;


font-weight:bold;


color:#1e1e1e;

}


.contentHeaderRight

{


position:relative;


float:right;


margin-right:6px;

}


.contentHeaderRight .arrowLeft{


position:relative;


float:left;


width: 27px;


height:20px;


background-image:url(/storage/MyCityInfoControl/arrows.png);


background-position:-4px -7px;


margin-right:4px;


margin-top:1px;


cursor:pointer;



}




.contentHeaderRight .arrowRight{


position:relative;


float:left;


width: 27px;


height:20px;


background-image:url(/storage/MyCityInfoControl/arrows.png);


background-position:-38px -7px;


margin-top:1px;


cursor:pointer;

}




.contentBody

{


padding:10px;


position:relative;


float:left;


font-size:12px;


font-color:#414141;


/*width:560px;*/

}


/*-------End Box Stucture-------*/



/*-------News Boxes-------*/



.contentIMG

{


position:relative;


float:left;


width:130px;


margin-right:10px;


text-align:center;

}


.contentIMG

img{


border:solid 3px #dadada!important;

}


.bigNews

{


position:relative;


float:left;


width:205px;


margin-right:25px;


line-height:15px;

}


.smallNewsWrapper

{


list-style:none;


margin:0;


padding:0;


width:190px;


position:relative;


float:left;

}


.smallnews

{


list-style:none;


margin:0;


padding:0;


width:190px;

}


.smallnews

li{


border-bottom:1px #CCC dashed;


margin-bottom:6px;


position:relative;


float:left;


padding-bottom:6px;


width:190px;



}

 


.newsHeader

{




color:#1e1e1e;


font-weight:bold;


position:relative;


float:left;


width:100%;

}


.newsSubHeader

{


color:#890c00;


font-weight:bold;


position:relative;


float:left;


width:100%;

}


.bigNews

.newsSubHeader{


margin-bottom:15px;

}

 


/*-------end News Boxes-------*/






/*-------Advert Plus Box-------*/






.advertPlusSliderWrapper

{


width:600px;




position:relative;


float:left;


margin-right:10px;


top:25px;


overflow:hidden;

}




.adSlider{


list-style:none;


width:99999px;


margin:0;


padding:0;


left:-120px;


position:relative;

}




.adSlide{


position:relative;


float:left;


margin:0 10px 0 10px;


width:100px;



}




.adimg{


position:relative;


float:left;


height:75px;


width:100px;

}




.adimg img{


position:absolute;


bottom:0;

}




.adCategory{


position:relative;


float:left;


width:100%;


clear:both;


text-align:center;


margin-top:5px;


color:#8f8f8f;


font-size:10px;

}




.adCompany{


position:relative;


float:left;


width:100%;


clear:both;


text-align:center;


color:#890c00;


font-size:10px;


font-weight:bold;

}




.adArrows{


position:relative;


float:left;


top:60px;


margin-top:1px;



}




.adArrows .leftArrow{


background-image:url(/storage/MyCityInfoControl/arrows.png);


background-position:-3px -40px;


cursor:pointer;


width: 37px;


height:28px;


position:relative;


margin-right:4px;

}






.adArrows .rightArrow{


background-image:url(/storage/MyCityInfoControl/arrows.png);


background-position:-48px -40px;


cursor:pointer;


width: 37px;


height:28px;


position:relative;

}




.adCategoryList{


position:relative;


float:left;


width:130px;


border-left:1px #CCC dashed;


margin-left:10px;


padding-right:20px;


top:10px;

}




.adCategoryList ul{


list-style:none;


margin:0;


padding:0 0 0 20px;

}




.adCategoryList li{


margin-bottom:10px;

}




.advertPlus{


height:200px!important;



}




/*-------end Advert Plus Box-------*/



/*-------Single Images Box-------*/




.imagebox{


width:260px;

}




.center{


text-align:center;

}




.allLink{


position:relative;


float:right;


text-align:left;


margin-top:5px;


font-size:10px;



}


/*-------end Single Images Box-------*/



 


/*-------Single ePaper Box-------*/




.ePaperThumb{


position:relative;


float:left;


width:80px;


text-align:center;



}




.ePaperContent{


position:relative;


float:left;


margin-left:10px;


width: 170px;

}




.ePaperLinks{


position:relative;


float:left;


clear:both;


margin-top:10px;

}




.ePaperList {


list-style:none;


margin:0;


padding:0;


width:260px;

}




.ePaperList li{


margin-bottom:5px;

}




/*-------endSingle ePaper Box-------*/



.halfInside

{


position:relative;


float:left;


text-align:center;


width:130px;



}


.halflist

{


position:relative;


float:left;


width:130px;

}


.halflist

ul{


list-style:none;


margin:0;


padding:0;


font-size:11px;



}


.halflist

ul li{


margin-bottom:20px;



}


.halflist

ul li a{


color:#414141;



}


/*-------Image and Video Boxes-------*/




.slideWrapper{


position:relative;


float:left;


text-align:center;


width:125px;


margin:0 5px 0 5px;

}




.mediaTitle{


font-size:10px;


font-weight:bold;


color:#890c00;


position:relative;


float:left;


clear:both;


text-align:center;


width:100%;

}




.mediaDate{


font-size:10px;


color:#8f8f8f;


margin-top:10px;


position:relative;


float:left;


clear:both;


text-align:center;


width:100%;

}




.slideWrapper img{


border:solid 3px #dadada;

}




.mediaBox{


height:170px;

}




/*-------end Image and Video Boxes-------*/



/*-------Event Box-------*/




.selectEventDate{


padding-top:1px;

}




.selectEventDate input,.selectEventDate select{


position:relative;


float:left;


margin-right:6px;


top:-1px;

}




.datePicker{


position:relative;


float:left;


margin-right:6px;


width:17px;


height:17px;


background-image:url(/storage/MyCityInfoControl/dpicon.png);

}




/*-------end Event Box-------*/








/*-------Lokalmatador Ad Box-------*/



.adBox

{


position:relative;


float:left;


width:580px;


height:190px;


background-color:#f6f6f6;


margin-right:10px;


margin-left:10px;


margin-bottom:20px;

}


/*-------end Lokalmatador Ad Box-------*/



 


/*-------Link Styles-------*/



.meinOrt

a,.meinOrtBox a{


color: #890c00;


text-decoration:none;

}


.headerMore

{


font-weight:normal;


margin-left:5px;


position:relative;


font-weight:bold;

}


.categoryLinks

{


font-size:10px;


position:relative;


float:left;


padding-top:5px

}




.categoryLinks a{


color:#505050;

}




.categoryLinks .activeCategory{


color:#890c00;

}




.videoLink{


font-size:11px;


color:#ffffff;


margin-left:5px;


position:relative;


float:left;


top:10px;


margin-left:10px;

}




.videoLink a{




color:#ffffff;



}




/*-------end Link Styles-------*/



 


/*-------Top Events-------*/



.topEvent

{


position:relative;


float:left;


margin-bottom:5px;



}


.topEventImg

{


position:relative;


float:left;


width: 60px;


text-align:center;



}


.topEventTitle

{


position:relative;


float:left;


width:200px;


font-size:10px;



}


/*-------end Top Events-------*/



 

 


/*-------PremiumAds-------*/



.premiumAds

{


position:relative;


float:left;


margin-bottom:10px;



}


.premiumImg

{


position:relative;


float:left;


width: 60px;


text-align:center;



}


.premiumTitle

{


position:relative;


float:left;


width:190px;


font-size:11px;


margin-left:10px;



}






.premiumTitle a{


color: #414141;



}


/*-------end Top Events-------*/



.smallerheight

{


height:187px!important;





}


.meinOrtBox

.cityName{


font-size:10px;

}

 

 


.button

{


height:23px;


cursor:pointer;


position:relative;


float:left;

}

 

 


.button

.Start {


position:relative;


float:left;


background-position:0 0;


background-image:url(/storage/MyCityInfoControl/buttonSprite.png);


width:4px;


height:23px;

}


.button

.Middle

{


position:relative;


float:left;


background-position:0px 118px;


background-image:url(/storage/MyCityInfoControl/buttonSprite.png);


padding:5px 5px 0 5px;


height:18px;


color:#ffffff;

}


.button

.End

{


position:relative;


float:left;


background-position:0 23px;


background-image:url(/storage/MyCityInfoControl/buttonSprite.png);


width:4px;


height:23px;

}


.poll

{


width:260px;


background-color:#f6f6f6;

}


.pollQuestion

{


width:260px;


position:relative;


float:left;


margin-bottom:10px;


margin-top:10px;

}


.poll

input[type=radio]{


position:relative;


float:left;


width:15%;



}


.poll

label{


position:relative;


float:left;


width:80%



}

 


.grayborder

img{


border:solid 3px #dadada;

}

 


.selectEventDate

input[type=submit]

{


position:relative;


float:left;


background-position:0px 118px;


background-image:url(/storage/MyCityInfoControl/buttonSprite.png);


height:23px;


color:#ffffff;


border:none;


margin:0;


top:0px;

}


.selectEventDate

.button{


top:-1px;

}