<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-877394266129021595</id><updated>2011-07-08T07:09:32.665-07:00</updated><category term='gridview'/><category term='c#'/><category term='VPN'/><category term='asp.net'/><category term='templated'/><category term='SiteMap'/><category term='custom control'/><category term='Attribute'/><category term='datacontrolfield'/><title type='text'>ASP.NET and C# Development</title><subtitle type='html'>ASP.NET and C# Development, Tips and Tricks, Custom Web Controls,</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-877394266129021595.post-3350262027760365934</id><published>2009-10-28T21:40:00.001-07:00</published><updated>2009-11-03T21:01:25.816-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SiteMap'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='Attribute'/><title type='text'>SiteMap Custom Attributes</title><content type='html'>&lt;p&gt;In this example we will use a custom attribute to hide some SiteMapNodes from a Menu control.    &lt;br /&gt;You can create custom attributes in a sitemap file easily as follows:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 10px 0px; padding-left: 4px; width: 97.64%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; height: 235px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMap&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://schemas.microsoft.com/AspNet/SiteMap-File-1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt; &lt;span style="color: #ff0000"&gt;url&lt;/span&gt; &lt;span style="color: #0000ff"&gt;=&amp;quot;./Default.aspx&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Find Equipment&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Find Equipment&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt; &lt;span style="color: #ff0000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;./RentProductPage.aspx&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Make Reservation&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Make Reservation&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt; &lt;span style="color: #ff0000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;./SearchResults.aspx&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Search Results&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Search results&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;IsMenuVisible&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt; &lt;span style="color: #ff0000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;./ProductDetails.aspx&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Product Details&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Product Details&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt; &lt;span style="color: #ff0000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;./ManageEquipment.aspx&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Manage Equipment&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Manage Equipment&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt; &lt;span style="color: #ff0000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;./SampleContract.aspx&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;View Sample Contract&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;View Sample Contract&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMapNode&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;siteMap&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;On the SearchResults.aspx node there is a custom attribute called “IsMenuVisible”. The “IsMenuVisible” attribute has been set to “False” since we do not want this node showing in the nav menu.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"&gt;This attribute can easily be accessed from the MenuItemDataBound event in the codebehind as follows:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; navMenu_MenuItemDataBound(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, MenuEventArgs e)&lt;br /&gt;{&lt;br /&gt;    SiteMapNode node = ((SiteMapNode) e.Item.DataItem);&lt;br /&gt;    MenuItem parentItem = e.Item.Parent;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; isMenuVisible = node[&lt;span style="color: #006080"&gt;&amp;quot;IsMenuVisible&amp;quot;&lt;/span&gt;];&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isMenuVisible != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (isMenuVisible.ToUpper() == &lt;span style="color: #006080"&gt;&amp;quot;FALSE&amp;quot;&lt;/span&gt;)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (parentItem != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                parentItem.ChildItems.Remove(e.Item);&lt;br /&gt;            }&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                navMenu.Items.Remove(e.Item);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"&gt;In the above example we cast “e.Item.DataItem” back to a SiteMapNode and access the custom attribute through it’s string index.&amp;#160; The remaning code is used to remove it from the Menu&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/877394266129021595-3350262027760365934?l=csaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/3350262027760365934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=877394266129021595&amp;postID=3350262027760365934' title='37 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/3350262027760365934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/3350262027760365934'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/2009/10/sitemapnode-custom-attributes.html' title='SiteMap Custom Attributes'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>37</thr:total></entry><entry><id>tag:blogger.com,1999:blog-877394266129021595.post-3065101936368191113</id><published>2009-09-09T20:49:00.001-07:00</published><updated>2009-09-09T20:49:43.942-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='custom control'/><title type='text'>ASP.NET Confirmation LinkButton</title><content type='html'>Below is the code to a very simple and reusable Confirmation LinkButton. Basically the control emits the standard &amp;quot;Are you sure?&amp;quot; type text before actually submitting the event allowing the user to click &amp;quot;Ok&amp;quot; or &amp;quot;Cancel&amp;quot;. Just create a new .CS file and copy/paste the code below into the file. This will create the new control. Here it is:   &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; height: 672px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 1000px; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ComponentModel;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web.UI;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; CreateSoftwareUtils.Web.Controls&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ConfirmLinkButton:LinkButton&lt;br /&gt;    {&lt;br /&gt;        [&lt;br /&gt;        Browsable(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;),&lt;br /&gt;        PersistenceMode(PersistenceMode.Attribute),&lt;br /&gt;        Themeable(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;        ]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ConfirmationText&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; confirmationText = ViewState[&lt;span style="color: #006080"&gt;&amp;quot;ConfirmationText&amp;quot;&lt;/span&gt;].ToString();&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (String.IsNullOrEmpty(confirmationText))&lt;br /&gt;                    confirmationText = &lt;span style="color: #006080"&gt;&amp;quot;Are you sure?&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; confirmationText;&lt;br /&gt;            }&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                ViewState[&lt;span style="color: #006080"&gt;&amp;quot;ConfirmationText&amp;quot;&lt;/span&gt;] = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPreRender(EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.OnClientClick = String.Format(&lt;span style="color: #006080"&gt;&amp;quot;return confirm(\&amp;quot;{0}\&amp;quot;);&amp;quot;&lt;/span&gt; + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.OnClientClick,ConfirmationText);            &lt;br /&gt;            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnPreRender(e);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can then reference this control in your page like any other normal LinkButton. Except there is a new property called &amp;quot;ConfirmationText&amp;quot; that you can set to specify a confirmation message, or just let it default to &amp;quot;Are you sure?&amp;quot;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/877394266129021595-3065101936368191113?l=csaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/3065101936368191113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=877394266129021595&amp;postID=3065101936368191113' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/3065101936368191113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/3065101936368191113'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/2009/09/aspnet-confirmation-linkbutton.html' title='ASP.NET Confirmation LinkButton'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-877394266129021595.post-6517662970975952168</id><published>2009-08-26T20:36:00.000-07:00</published><updated>2009-08-26T22:02:17.327-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='gridview'/><category scheme='http://www.blogger.com/atom/ns#' term='datacontrolfield'/><category scheme='http://www.blogger.com/atom/ns#' term='custom control'/><title type='text'>ASP.NET GridView Confirm Delete Button Field</title><content type='html'>&lt;div&gt;Here is a quick and easy reusable "ConfirmButtonField" for use on an ASP.NET GridView&lt;/div&gt;&lt;br /&gt;&lt;div style="margin: 0in 0in 10pt;"&gt;&lt;u&gt;Just simply derive from ButtonField and override a couple things:&lt;/u&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;using&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; System;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;using&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; System.Collections.Generic;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;using&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; System.Linq;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;using&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; System.Text;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;using&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; System.Web.UI;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;using&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; System.Web.UI.WebControls;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;namespace&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; CreateSoftwareUtils.Web.GridViewControls&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;public &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af; font-size: 10pt;"&gt;ConfirmButtonField&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; : &lt;/span&gt;&lt;span style="color: #2b91af; font-size: 10pt;"&gt;ButtonField&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;public &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;override &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;void&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; InitializeCell(&lt;/span&gt;&lt;span style="color: #2b91af; font-size: 10pt;"&gt;DataControlFieldCell&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; cell, &lt;/span&gt;&lt;span style="color: #2b91af; font-size: 10pt;"&gt;DataControlCellType&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; cellType, &lt;/span&gt;&lt;span style="color: #2b91af; font-size: 10pt;"&gt;DataControlRowState&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; rowState, &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;int&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt; rowIndex)&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;base&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt;.InitializeCell(cell, cellType, rowState, rowIndex);&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;if&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt;(cellType == &lt;/span&gt;&lt;span style="color: #2b91af; font-size: 10pt;"&gt;DataControlCellType&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt;.DataCell)&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cell.Attributes.Add(&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;"onclick"&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt;,&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;"return confirm(\"Are you sure?\");"&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt;);&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;u&gt;&lt;span style="color: black;"&gt;Then on the ASPX page you can do this:&lt;/span&gt;&lt;/u&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;asp&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;:&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;GridView&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;ID&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="gvEquipment"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;runat&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="server"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="false"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;DataKeyNames&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="ProductId"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;Columns&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;cs&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;:&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;ConfirmButtonField &lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;ButtonType&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Link"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;Text&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Delete"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;CommandName&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Delete"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;asp&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;:&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;ButtonField &lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;ButtonType&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Link"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;Text&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="View/Edit"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;CommandName&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Select"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;asp&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;:&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;BoundField &lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;DataField&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Name"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;HeaderText&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Title"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;HeaderStyle-Width&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="300px"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;ItemStyle-Width&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="300px"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;ItemStyle-Wrap&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="true"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;asp&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;:&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;BoundField &lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;DataField&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="PriceDaily"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;HeaderText&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="Daily Rate"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;DataFormatString&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="{0:c}"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;HeaderStyle-Width&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;="80px"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;Columns&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;asp&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;:&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;GridView&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;b&gt;&lt;u&gt;I also like to register controls I am going to use all over the site in the Web.Config like this:&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;/div&gt;&lt;div style="background: white; line-height: normal; margin: 0in 0in 0pt;"&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515; font-size: 10pt;"&gt;add &lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;tagPrefix&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: #666666; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;cs&lt;/span&gt;&lt;span style="color: #666666; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;namespace&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: #666666; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;CreateSoftwareUtils.Web.GridViewControls&lt;/span&gt;&lt;span style="color: #666666; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: red; font-size: 10pt;"&gt;assembly&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;=&lt;/span&gt;&lt;span style="color: #666666; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;CreateSoftwareUtils&lt;/span&gt;&lt;span style="color: #666666; font-size: 10pt;"&gt;"&lt;/span&gt;&lt;span style="color: blue; font-size: 10pt;"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin: 0in 0in 10pt;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/877394266129021595-6517662970975952168?l=csaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/6517662970975952168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=877394266129021595&amp;postID=6517662970975952168' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/6517662970975952168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/6517662970975952168'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/2009/08/aspnet-gridview-confirm-delete-button.html' title='ASP.NET GridView Confirm Delete Button Field'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-877394266129021595.post-4793455479954455867</id><published>2008-11-19T12:22:00.000-08:00</published><updated>2009-09-09T10:07:53.204-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VPN'/><title type='text'>Browse the Internet while connected through VPN</title><content type='html'>A common scenario for developers and other IT professionals is to work remotely via terminal services (remote desktop) through a VPN connection. One problem I'm sure everyone has expererienced (besides it being slow) is that by default it is not possible to browse the internet or keep Microsoft Outlook connections established once you have established the VPN connection to the server. Luckily, there is actually an easy solution to this problem!&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;The lies in the routing table. By default once the VPN connection is formed the routing table is modified so that all outbound packets are sent to the VPN servers gateway address instead of your own gateway which would lead to the internet.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;To correct this issue in Windows XP simply open the properties for the VPN connection (by right-clicking the VPN connection icon and choosing properties) and then select the "Networking" tab:&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/_1wKylu6pQXY/SSu4t8-HsSI/AAAAAAAAABM/2ANx_AgyQ-I/s1600-h/Step+1.jpg"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5272510888367599906" src="http://4.bp.blogspot.com/_1wKylu6pQXY/SSu4t8-HsSI/AAAAAAAAABM/2ANx_AgyQ-I/s320/Step+1.jpg" style="cursor: hand; height: 320px; width: 261px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Next select "Internet Protocol (TCP/IP)" and press the properties button which opens a new window with TCP/IP properties, you will then need to click on advanced:&lt;/div&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/_1wKylu6pQXY/SSu5bsy0PsI/AAAAAAAAABU/ue2LSGTzN7Q/s1600-h/Step+2.jpg"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5272511674299203266" src="http://4.bp.blogspot.com/_1wKylu6pQXY/SSu5bsy0PsI/AAAAAAAAABU/ue2LSGTzN7Q/s320/Step+2.jpg" style="cursor: hand; height: 320px; width: 284px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;And finally we make it to the magic checkbox that will make your life easier. &lt;strong&gt;Un&lt;/strong&gt;check "Use default gateway on remote network". One this has been disabled you should find that browsing the internet while also being connected to a VPN server is no longer issue.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_1wKylu6pQXY/SSu6SzaJw8I/AAAAAAAAABc/pz-znmaKT_o/s1600-h/Step+3.jpg"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5272512620967609282" src="http://2.bp.blogspot.com/_1wKylu6pQXY/SSu6SzaJw8I/AAAAAAAAABc/pz-znmaKT_o/s320/Step+3.jpg" style="cursor: hand; height: 320px; width: 265px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Hope this helps! Haven't tried this under Vista, leave a comment and let me know if it is the same...&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Thanks&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://3.bp.blogspot.com/_1wKylu6pQXY/SSu4dSA4GzI/AAAAAAAAABE/csF4Fo_tSBs/s1600-h/Step+1.jpg"&gt;&lt;/a&gt;&lt;a href="http://3.bp.blogspot.com/_1wKylu6pQXY/SSu4dSA4GzI/AAAAAAAAABE/csF4Fo_tSBs/s1600-h/Step+1.jpg"&gt;&lt;/a&gt;&lt;a href="http://3.bp.blogspot.com/_1wKylu6pQXY/SSu4dSA4GzI/AAAAAAAAABE/csF4Fo_tSBs/s1600-h/Step+1.jpg"&gt;&lt;/a&gt;&lt;a href="http://3.bp.blogspot.com/_1wKylu6pQXY/SSu4dSA4GzI/AAAAAAAAABE/csF4Fo_tSBs/s1600-h/Step+1.jpg"&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/877394266129021595-4793455479954455867?l=csaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/4793455479954455867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=877394266129021595&amp;postID=4793455479954455867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/4793455479954455867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/4793455479954455867'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/2008/11/browse-internet-while-connected-to-vpn.html' title='Browse the Internet while connected through VPN'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_1wKylu6pQXY/SSu4t8-HsSI/AAAAAAAAABM/2ANx_AgyQ-I/s72-c/Step+1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-877394266129021595.post-5390671695621803212</id><published>2008-11-14T00:19:00.000-08:00</published><updated>2008-11-14T00:34:56.650-08:00</updated><title type='text'>Tip for Managing Keys for QueryString, ViewState, Session, Etc.</title><content type='html'>When developing web applications you always have to manage all those "names" for the QueryString, ViewState, Session, etc. and its good to have consistent and "typed" way to too keep track of that stuff.&lt;br /&gt;&lt;br /&gt;To manage this information on a per page basis I simply create private classes within the page so I can have a typed way of accessing these keys. For example:&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; GTTPatentSearchWeb.Search&lt;br /&gt;{&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ViewPatent : System.Web.UI.Page&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; QueryStringKeys&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; PatentId = &lt;span class="str"&gt;"PatentId"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; UserId = &lt;span class="str"&gt;"Uid"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; RegionId = &lt;span class="str"&gt;"Rid"&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ViewStateKeys&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SelectedPatentId = &lt;span class="str"&gt;"SelPatentId"&lt;/span&gt;;&lt;br /&gt;            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; IsNew = &lt;span class="str"&gt;"IsNew"&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; PatentId&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;object&lt;/span&gt; patentId = Request.QueryString[QueryStringKeys.PatentId];&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (patentId != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ToInt32(patentId);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; -1;&lt;br /&gt;            }&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;As you can see this provides a nice typed method for managing keys rather than trying to remember the names you used throughout the page.&lt;br /&gt;For SessionKeys I generally will create a global class in App_Code to manage the SessionKeys since they cross page and not specific to the page itself. This prevents me from accidentally using a SessionKey in 2 places in application not realizing it had already been used.&lt;br /&gt;&lt;br /&gt;Have a great day!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/877394266129021595-5390671695621803212?l=csaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/5390671695621803212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=877394266129021595&amp;postID=5390671695621803212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/5390671695621803212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/5390671695621803212'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/2008/11/managing-querystring-viewstate-session.html' title='Tip for Managing Keys for QueryString, ViewState, Session, Etc.'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-877394266129021595.post-9065809953855930099</id><published>2008-10-16T22:29:00.000-07:00</published><updated>2009-08-30T18:42:14.498-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='asp.net'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='templated'/><category scheme='http://www.blogger.com/atom/ns#' term='custom control'/><title type='text'>Creating Easy ASP.NET Custom Web Controls</title><content type='html'>&lt;div&gt;public void Warning()&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;WARNING:&lt;/span&gt; This is my first post so I apologize in advance for any strange formatting &lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;errors you may experience and also my inability to write complete sentences or sometimes &lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;just keep on going and never acutally end the sentence making for a very long sentence &lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;that just goes on and on and on and on, and on... ;-)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;*/&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;throw new BadWriterException("Keep your day job!");&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Overview&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;In this quick article I am going to show you a method I use to quickly make "Custom Web Controls" without having to deal with manually building the layout declaritvely in code or by hardcoding the markup directly into the control. &amp;nbsp;&lt;/div&gt;&lt;div&gt;This will essentially be accomplished by saving the control markup as a seperate file and marking the file as an&amp;nbsp;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;embedded resource&lt;/span&gt;&lt;span class="Apple-style-span"&gt;&amp;nbsp;within the web control project.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Sound interesintg, then read on...&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Let's Get Started&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Many times when I am working on an ASP.NET site I realize that one of my "UserControls" I have created in my web project would be extremely useful in my toolkit and warrants conversion into a "Custom Web Control".&lt;/div&gt;&lt;div&gt;"Custom Web Controls" have several advantages over "User Controls" such as: easier/reliable method of sharing across multiple projects/solutions and developers/people, and the ability to add more "Designer" features,&lt;span class="Apple-style-span" style="font-style: italic;"&gt; to name a few...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;After spending hours of tweaking the nuances of the visual portion of my "UserControl" I don't want to have to go back to square one and spend alot of time converting my XHTML markup to a declaritive control tree in code. &amp;nbsp;I also don't want to have to spend alot of time trying to get my markup to hard-code into the control which also makes it more difficult to manage.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;The solution I have created is to put the markup into a seperate ".txt" file and save it as an "Embedded Resource" in my custom web control project and then parse the control text dynamically at runtime.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; text-decoration: underline;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;So enough typing, lets look at some pictures!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;In the following pictures I will be demonstrating a simple templated container control with a "Header" and "Body". &amp;nbsp;I am generally buidling business applications and I use this type of control all the time to group sections of a page into logical sections.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;The final result looks like this:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0000ee;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;Example 1:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #0000ee;"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5257996154609957474" src="http://1.bp.blogspot.com/_1wKylu6pQXY/SPgnpQHlemI/AAAAAAAAAAM/prfyv7shru0/s320/Example1.jpg" style="cursor: pointer; margin: 0px 10px 10px 0px;" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;And of course you can change the style sheets and customize however you want:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Example 2:&lt;/div&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_1wKylu6pQXY/SPgpUuzJMVI/AAAAAAAAAAk/A2PUWqfdiqU/s1600-h/Example2.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5257998001091719506" src="http://2.bp.blogspot.com/_1wKylu6pQXY/SPgpUuzJMVI/AAAAAAAAAAk/A2PUWqfdiqU/s320/Example2.jpg" style="cursor: pointer;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;And here is what the usage looks like in an .ASPX or .ASCX:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/_1wKylu6pQXY/SPgqxvzb4II/AAAAAAAAAAs/fPw8ygbNM8k/s1600-h/ControlExample.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5257999599089213570" src="http://4.bp.blogspot.com/_1wKylu6pQXY/SPgqxvzb4II/AAAAAAAAAAs/fPw8ygbNM8k/s320/ControlExample.jpg" style="cursor: pointer;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Building the Control&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;To create this control you will need to create a custom webcontrol project and then create (2) files:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;One for the Control itself&lt;/li&gt;&lt;li&gt;and one more for the Control markup; which is just a .txt file&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Make to sure to right-click the Control markup file, choose properties, and sets its "Build Action" to "Embedded Resource"&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;When you're done it should something like this:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://2.bp.blogspot.com/_1wKylu6pQXY/SPgrMMXHv8I/AAAAAAAAAA0/Wiii9IDc2Z0/s1600-h/VSFolderStructure.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5258000053431680962" src="http://2.bp.blogspot.com/_1wKylu6pQXY/SPgrMMXHv8I/AAAAAAAAAA0/Wiii9IDc2Z0/s320/VSFolderStructure.jpg" style="cursor: pointer;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;And here is the control markup that gets placed into the SectionHeaderControl.txt file:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:panel&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;CssClass&lt;/span&gt;&lt;span class="kwrd"&gt;="sectionHeaderContainer"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:panel&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;CssClass&lt;/span&gt;&lt;span class="kwrd"&gt;="sectionHeaderTitleContainer"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;span&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="sectionHeaderTitleContainerCell"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="lblTitle"&lt;/span&gt; &lt;span class="attr"&gt;CssClass&lt;/span&gt;&lt;span class="kwrd"&gt;="sectionHeaderTitleText"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;span&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:panel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:panel&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;CssClass&lt;/span&gt;&lt;span class="kwrd"&gt;="sectionHeaderContentContainer"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:PlaceHolder&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="plContent"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:panel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:panel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Code&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Just like in most CustomControls the magic happens in the "CreateChildControls()" method. Here is the entire section of code in the "CreateChildControls()" method:&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; controlText = CSUtility.GetEmbeddedResource(&lt;span class="str"&gt;"CreateSoftwareUtils.Web.Controls.SectionHeaderControlText.txt"&lt;/span&gt;);&lt;br /&gt;ControlParser parser = &lt;span class="kwrd"&gt;new&lt;/span&gt; ControlParser();&lt;br /&gt;Control parsedMasterControl = parser.Parse(controlText);&lt;br /&gt;parsedMasterControl.ID = &lt;span class="str"&gt;"masterControl"&lt;/span&gt;;&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.Controls.Add(parsedMasterControl);&lt;br /&gt;&lt;br /&gt;_contentControls = parsedMasterControl.FindControl(&lt;span class="str"&gt;"plContent"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; PlaceHolder;&lt;br /&gt;Label lblTitle = parsedMasterControl.FindControl(&lt;span class="str"&gt;"lblTitle"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Label;&lt;br /&gt;&lt;br /&gt;lblTitle.Text = Title;&lt;br /&gt;&lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls();&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;So, as you can see, there isn't much to it!&lt;/div&gt;&lt;div&gt;I have wrapped a couple of generic things into some utlity classes so I don't have to keep typing the same stuff over and over again; also just in-case I change how I am accomplishing those particular tasks it will be an easy change across all the controls.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;The first is &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;CSUtility.GetEmbeddedResource()&lt;/span&gt;:&lt;/div&gt;&lt;div&gt;This method is responsible for getting the control text from the embedded resource and is pretty simple...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetEmbeddedResource(&lt;span class="kwrd"&gt;string&lt;/span&gt; resourceName)&lt;br /&gt;{&lt;br /&gt;Assembly assembly = Assembly.GetExecutingAssembly();&lt;br /&gt;Stream resourceStream = assembly.GetManifestResourceStream(resourceName);&lt;br /&gt;StreamReader reader = &lt;span class="kwrd"&gt;new&lt;/span&gt; StreamReader(resourceStream);&lt;br /&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; resourceText = reader.ReadToEnd();&lt;br /&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; resourceText;&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;The next is the "ControlParser" object. &amp;nbsp;Those of you who have used the "ParseControl()" method before probably did this on the "Page" object. &amp;nbsp;Unfortunatly the Page object is not available all the time, and so when one of the properties calls "EnsureChildControls()" we get a object null error.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;The ControlParser class inherits from the TemplateControl abstract class (same as Page) and is also quite simple. &amp;nbsp;Setting the .AppRelativeVirtualPath is what allows things to work correctly and not receive "virtualPath" errors:&lt;/div&gt;&lt;div&gt;Here is entire code base of that control:&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// Allows parsing of controls without an HttpContext or Page object&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// Normally ParseControl would be called from the Page object but thats&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// not possible when the Page object is not in scope/available&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ControlParser : TemplateControl, INamingContainer&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; Control Parse(&lt;span class="kwrd"&gt;string&lt;/span&gt; controlText)&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.AppRelativeVirtualPath = &lt;span class="str"&gt;"/"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.ParseControl(controlText);&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;Ok, now that you know the secret parts of the control lets go back and talk about the CreateChildControls() method, here it is again so you don't have to scroll up:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; controlText = CSUtility.GetEmbeddedResource(&lt;span class="str"&gt;"CreateSoftwareUtils.Web.Controls.SectionHeaderControlText.txt"&lt;/span&gt;);&lt;br /&gt;ControlParser parser = &lt;span class="kwrd"&gt;new&lt;/span&gt; ControlParser();&lt;br /&gt;Control parsedMasterControl = parser.Parse(controlText);&lt;br /&gt;parsedMasterControl.ID = &lt;span class="str"&gt;"masterControl"&lt;/span&gt;;&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.Controls.Add(parsedMasterControl);&lt;br /&gt;&lt;br /&gt;_contentControls = parsedMasterControl.FindControl(&lt;span class="str"&gt;"plContent"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; PlaceHolder;&lt;br /&gt;Label lblTitle = parsedMasterControl.FindControl(&lt;span class="str"&gt;"lblTitle"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Label;&lt;br /&gt;&lt;br /&gt;lblTitle.Text = Title;&lt;br /&gt;&lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls();&lt;br /&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;What's happening?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Basically heres what happens:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;(1): &lt;span class="Apple-tab-span" style="white-space: pre;"&gt;&lt;/span&gt;We get the control markup from the embedded resource&lt;/li&gt;&lt;li&gt;(2,3):&amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Use&amp;nbsp;ParserControl to create a new Control from the control markup&lt;/li&gt;&lt;li&gt;(4):&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Set the ID for fun&lt;/li&gt;&lt;li&gt;(5):&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Add the Control we just created dynamically to the Control Tree&lt;/li&gt;&lt;li&gt;(6,7):&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Get references to controls within the dynamic control so we can do stuff with them&lt;/li&gt;&lt;li&gt;(8):&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Set the title&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;This, to me, is a lot easier to look at than 300 lines of declartive C# code that creates a big long control tree!&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Full Source:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Here is the complete source of the control:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.ComponentModel.Design;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Reflection;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; CreateSoftwareUtils.Web.Controls&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SectionHeader : WebControl, INamingContainer&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _title;&lt;br /&gt;[&lt;br /&gt;Browsable(&lt;span class="kwrd"&gt;true&lt;/span&gt;),&lt;br /&gt;PersistenceMode(PersistenceMode.Attribute)]&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Title&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; _title;&lt;br /&gt;}&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;_title = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; PlaceHolder _contentControls;&lt;br /&gt;[PersistenceMode(PersistenceMode.InnerProperty)]&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; PlaceHolder ContentControls&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;EnsureChildControls();&lt;br /&gt;&lt;span class="kwrd"&gt;return&lt;/span&gt; _contentControls;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;br /&gt;{&lt;br /&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; controlText = CSUtility.GetEmbeddedResource(&lt;span class="str"&gt;"CreateSoftwareUtils.Web.Controls.SectionHeaderControlText.txt"&lt;/span&gt;);&lt;br /&gt;ControlParser parser = &lt;span class="kwrd"&gt;new&lt;/span&gt; ControlParser();&lt;br /&gt;Control parsedMasterControl = parser.Parse(controlText);&lt;br /&gt;parsedMasterControl.ID = &lt;span class="str"&gt;"masterControl"&lt;/span&gt;;&lt;br /&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.Controls.Add(parsedMasterControl);&lt;br /&gt;&lt;br /&gt;_contentControls = parsedMasterControl.FindControl(&lt;span class="str"&gt;"plContent"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; PlaceHolder;&lt;br /&gt;Label lblTitle = parsedMasterControl.FindControl(&lt;span class="str"&gt;"lblTitle"&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Label;&lt;br /&gt;&lt;br /&gt;lblTitle.Text = Title;&lt;br /&gt;&lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="text-decoration: underline;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Now you may be wondering why I didn't use ITemplate's and TemplateContainers for creating this templated control, here's why:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Anything contained within an ITemplate is not accessible from within the page unless you use FindControl() on the parent to locate what you need. &amp;nbsp;I find this to be very annoying and adds alot of ugly code in the back end to get references and you don't have intellisense available.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;[NOTE: it also possible to use ITemplate instead of PlaceHolder by setting the TemplateInstance.Single attribute on the property so that the internal Template controls would be accesible outside the container. &amp;nbsp;This is new in 2.0 and later]&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;By exposing a PlaceHolder as the Template instead of ITemplate inside the custom control, you still get to have Intellisence, normal control references, and everything just works as expected on&amp;nbsp;the consuming .ASPX/.ASCX page&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;One last thing, since I didn't create any "Designer" for this Control it of course doesn't render/pukes in the "Design" view of Visual Studio. &amp;nbsp;If you end up writing a designer for this control let me know and I will post it here for all to enjoy, including me! ;-)&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Let me know what you think of this article, the more responses/followers/comments I receive the more encouraged I will be to write another. &amp;nbsp;Unless of course the responses/comments are all "You Suck!" ;-)&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Thanks,&lt;/div&gt;&lt;div&gt;Joshua Mason&lt;/div&gt;&lt;div&gt;Senior Software Engineer&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/877394266129021595-9065809953855930099?l=csaspnet.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csaspnet.blogspot.com/feeds/9065809953855930099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=877394266129021595&amp;postID=9065809953855930099' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/9065809953855930099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/877394266129021595/posts/default/9065809953855930099'/><link rel='alternate' type='text/html' href='http://csaspnet.blogspot.com/2008/10/creating-easy-custom-web-cotnrols.html' title='Creating Easy ASP.NET Custom Web Controls'/><author><name>Josh Mason</name><uri>http://www.blogger.com/profile/01743986929541325605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_1wKylu6pQXY/SPgnpQHlemI/AAAAAAAAAAM/prfyv7shru0/s72-c/Example1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
