SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have another task at hand. I need to use cookies to read a title of an item from a custom list in SharePoint. This task is for SharePoint 2010.

I have a container set up that will display the two newest items. This container is being populated by a usercontrol and is using the ASP:Repeater control. In this control I have this:

asp:Literal ID="Literal1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Portal Content") %>' /> &nbsp; <asp:HyperLink ID="hlAssetUrl" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Asset Title") %>' NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Asset URL") %>' Target='<%# Convert.ToString(Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "Open in New Window")) ? "_blank" : "_top") %>' >

I am trying to set the Asset title in the hyper link as the cookie.

I have the GetCookie function and SetCookie function as follows:

unction SetCookie(cookieName, cookieValue, nDays) {

var today = new Date();

var expire = new Date();

if (nDays == null || nDays == 0) nDays = 1;

expire.setTime(today.getTime() + 3600000*24*nDays);

document.cookie = cookieName + "=" + escape(cookieValue)

+ ";expires=" + expire.toGMTString();


function ReadCookie(cookieName) {

var theCookie = " " + document.cookie;

var ind = theCookie.indexOf(" " + cookieName + "=");

if (ind == -1) ind = theCookie.indexOf(";" + cookieName + "=");

if (ind == -1 || cookieName == "") return "";

var ind1 = theCookie.indexOf(";", ind + 1);

if (ind == -1) ind1 = theCookie.length;

return unescape(theCookie.substring(ind + cookieName.length + 2, ind1));


Any lead way would be greatly appreciated.

share|improve this question
So what's the problem? – SHug Jan 23 '12 at 15:43
How do i make cookie equal to the title that is being brought in by the user control? – James Jan 23 '12 at 18:39

I honestly don't get why you are using javascript to set/get this cookie if you're going to need them severside anyways?


var cookie = new HttpCookie("MyCookie") { Value = "Hey", Expires = DateTime.Now.AddMinutes(10), Path = "/" };


if (Page.Request.Cookies.Count > 0)
    var cookie = Page.Request.Cookies["Name of cookie here"].Values;

Now you can use it however you please in your usercontrol. Javascript is a bit overkill in this situation, unless of course you disregard postbacks.

Hope this helps :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.