Archived entries for Uncategorized

Access control in masterpage from content page

Here is a nice easy one, if you have a control in your .master file that you need to access from your content page you can do the following to manipulate that control.

 
// Create a new object that relates to your .master file control and call the FindControl function to return its properties
Xml xMasterHeaderXML = (Xml)Master.FindControl("xmlHeader");
 
// Do a basic is null check to see if hte control is there or not
if (xMasterHeaderXML != null)
{
     // Set whatever properties and values you need.
     xMasterHeaderXML.DocumentContent = "<root></root>";
     xMasterHeaderXML.TransformSource = "xsl/header.xsl";
}
 

Create a cookie and read it back in C#

Been a bit bare at the mo, lots of dev work going on so thought I would fill it with a simple how to with Cookies.

To create a cookie on your site...

 
// Lets check if it exists or not yet.
if (Request.Cookies["MySite_LastVisit"] == null)
{
 
// Create new Cookie object to store users last visit to the site.
HttpCookie ckUserLastVisit = new HttpCookie("MySite_LastVisit");
 
// Get current date/time
DateTime dtNow = DateTime.Now;
 
// Set the cookie value.
ckUserLastVisit.Value = dtNow.ToString();
 
// Set the cookie expiration date. We will say one day from now
// but you could say as long as you want.
ckUserLastVisit.Expires = dtNow.AddDays(1);
 
// Add the cookie.
Response.Cookies.Add(ckUserLastVisit);
 
}

So that is it created. Lets see how to read that information back.

 
if (Request.Cookies["MySite_LastVisit"] == null)
{
// Just assign our value to a new string and then do what we want with it.
String sLastVisitDate = Request.Cookies["MySite_LastVisit"].Value;
}
 

That should be it, nice and simple.

Welcome

Okay so here is the start of what I want to be a log/portfolio of everything that I am doing with regards to developing websites and give people who are interested in using my skills or interested in how certain sites are progressing and my thoughts for them.



Copyright © 2004–2009. All rights reserved.

RSS Feed. This blog is proudly powered by Wordpress and uses Modern Clix, a theme by Rodrigo Galindez.