by pietman
21. May 2010 14:19
PostList1.Posts = Post.Posts.ConvertAll(new Converter<Post, IPublishable>
(delegate(Post p) { return p as IPublishable; }));
public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter);
0950aad7-ccc1-43d9-9308-ac29537f9daf|0|.0
Tags:
by pietman
21. May 2010 13:07
use the following CSS in your stylesheet:
body
{
margin: 0px auto; /* this is what does the trick */
padding: 0px;
width: 800px;
}
2ba1007f-bba2-4069-a4d0-26432ad0e3ba|0|.0
Tags:
by pietman
21. May 2010 11:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class BasePage : System.Web.UI.Page
{
#region Overridden Page Events
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// Start measuring page execution time
if (this.MeasureExecutionTime)
{
watch = new Stopwatch();
watch.Start();
this.RecordTimestamp("Page execution starting...");
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Set the page title
this.SetPageTitle();
}
protected override void OnPreRenderComplete(EventArgs e)
{
base.OnPreRenderComplete(e);
if (this.MeasureExecutionTime)
{
this.RecordTimestamp("Page execution complete...");
watch.Stop();
Control addExecutionTo = this.Form;
if (addExecutionTo == null)
addExecutionTo = this;
addExecutionTo.Controls.Add(new LiteralControl("<br /><br />"));
StringBuilder timestampsOutput = new StringBuilder(50 * this.ExecutionTimestamps.Count);
for (int i = 0; i < this.ExecutionTimestamps.Count; i++)
timestampsOutput.AppendFormat("<b>Timestamp {0}</b>: {1:N0} ms ({2})<br />{3}",
i + 1, this.ExecutionTimestamps[i].Timestamp,
this.ExecutionTimestamps[i].Description, Environment.NewLine);
addExecutionTo.Controls.Add(new LiteralControl(timestampsOutput.ToString()));
}
}
#endregion
#region DisplayAlert
protected virtual void DisplayAlert(string message)
{
ClientScript.RegisterStartupScript(
this.GetType(),
Guid.NewGuid().ToString(),
string.Format("alert('{0}');", message.Replace("'", @"\'")),
true
);
}
#endregion
#region FindControlRecursive
protected virtual Control FindControlRecursive(string id)
{
return FindControlRecursive(id, this);
}
protected virtual Control FindControlRecursive(string id, Control parent)
{
// If parent is the control we're looking for, return it
if (string.Compare(parent.ID, id, true) == 0)
return parent;
// Search through children
foreach (Control child in parent.Controls)
{
Control match = FindControlRecursive(id, child);
if (match != null)
return match;
}
// If we reach here then no control with id was found
return null;
}
#endregion
#region SetPageTitle
protected virtual bool AutoSetPageTitle
{
get
{
object o = ViewState["AutoSetPageTitle"];
if (o == null)
return true;
else
return (bool)o;
}
set
{
ViewState["AutoSetPageTitle"] = value;
}
}
protected virtual string SiteMapProvider
{
get
{
string str = ViewState["SiteMapProvider"] as string;
if (str == null)
return string.Empty;
else
return str;
}
set
{
ViewState["SiteMapProvider"] = value;
}
}
protected virtual string SiteMapNodeSeparator
{
get
{
string str = ViewState["SiteMapNodeSeparator"] as string;
if (str == null)
return " :: ";
else
return str;
}
set
{
ViewState["SiteMapNodeSeparator"] = value;
}
}
protected virtual void SetPageTitle()
{
if (this.AutoSetPageTitle && (string.IsNullOrEmpty(this.Title) || string.Compare(this.Title, "Untitled Page", true) == 0))
{
if (SiteMap.Enabled)
{
// See if this page is in the SiteMap
SiteMapNode current = null;
if (string.IsNullOrEmpty(this.SiteMapProvider))
current = SiteMap.CurrentNode;
else
current = SiteMap.Providers[this.SiteMapProvider].CurrentNode;
if (current != null)
{
// Build up the title
SetPageTitle(current);
return;
}
}
// If we reach here we still do not have a title set... use the filename
this.Title = Path.GetFileNameWithoutExtension(Request.PhysicalPath);
}
}
protected virtual void SetPageTitle(SiteMapNode current)
{
if (this.AutoSetPageTitle)
{
StringBuilder titleBuilder = new StringBuilder(200);
titleBuilder.Append(current.Title);
current = current.ParentNode;
if (current != null)
{
string parentPathReverse = current.Title;
while (current.ParentNode != null)
{
current = current.ParentNode;
parentPathReverse = string.Concat(current.Title, this.SiteMapNodeSeparator, parentPathReverse);
}
titleBuilder.Append(" (").Append(parentPathReverse).Append(")");
}
this.Title = titleBuilder.ToString();
}
}
#endregion
#region ExecutionTime
protected virtual bool MeasureExecutionTime
{
get
{
object o = ViewState["MeasureExecutionTime"];
if (o == null)
return false;
else
return (bool)o;
}
set
{
ViewState["MeasureExecutionTime"] = value;
}
}
private Stopwatch watch = null;
private List<TimestampInfo> timestamps = null;
protected virtual List<TimestampInfo> ExecutionTimestamps
{
get
{
if (timestamps == null)
timestamps = new List<TimestampInfo>();
return timestamps;
}
}
protected virtual void RecordTimestamp(string description)
{
if (watch == null)
throw new ArgumentException("In order to record page execution time MeasureExecutionTime must be set to True.");
ExecutionTimestamps.Add(new TimestampInfo(watch.ElapsedMilliseconds, description));
}
#endregion
}
c4e35283-ed69-42c5-bf39-f2175477b1aa|0|.0
Tags: