<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stephen Lacy &#187; Web Forms</title>
	<atom:link href="http://www.lacy.ie/tag/web-forms/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lacy.ie</link>
	<description>Impressions as an ASP.Net Developer</description>
	<lastBuildDate>Mon, 05 Jul 2010 09:26:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Redirecting using strong types in an asp.net web application project</title>
		<link>http://www.lacy.ie/redirecting-using-strong-types-in-an-asp-net-web-application-project</link>
		<comments>http://www.lacy.ie/redirecting-using-strong-types-in-an-asp-net-web-application-project#comments</comments>
		<pubDate>Wed, 13 Jan 2010 18:45:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Resharper]]></category>
		<category><![CDATA[Web Application Projects]]></category>
		<category><![CDATA[Web Forms]]></category>

		<guid isPermaLink="false">http://www.lacy.ie/?p=249</guid>
		<description><![CDATA[Update, I recommend also reading the following post after you read this one if you plan on using this within .Net 4: http://www.lacy.ie/updating-redirection-using-strong-types-to-net-4 It recently began to annoy me that every time I want to redirect to a page I have to use a string. Not a big deal I know but when you have broken [...]


Related posts:<ol><li><a href='http://www.lacy.ie/how-to-mock-the-httpcontext-in-asp-net' rel='bookmark' title='Permanent Link: How to Mock the HttpContext in asp.net'>How to Mock the HttpContext in asp.net</a> <small>I find mocking the http context rather difficult, you can&#8217;t...</small></li>
<li><a href='http://www.lacy.ie/jquery-grid-plugin-jqgrid-with-asp-net-web-forms' rel='bookmark' title='Permanent Link: jQuery Grid Plugin (JqGrid) with ASP.Net Web Forms'>jQuery Grid Plugin (JqGrid) with ASP.Net Web Forms</a> <small>Get JqGrid here: http://www.trirand.com/blog/ So far I&#8217;ve seen two implementations...</small></li>
<li><a href='http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms' rel='bookmark' title='Permanent Link: Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms'>Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms</a> <small>I had a problem where I wanted to use the...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Update, I recommend also reading the following post after you read this one if you plan on using this within .Net 4: <a href="http://www.lacy.ie/updating-redirection-using-strong-types-to-net-4">http://www.lacy.ie/updating-redirection-using-strong-types-to-net-4</a></p>
<p>It recently began to annoy me that every time I want to redirect to a page I have to use a string. Not a big deal I know but when you have broken links it can reflect badly on you as a developer, so I began to look for some solution that would allow for the following.</p>
<ul>
<li>Refactoring: I need to be able to move a page around without having to find every string reference to it</li>
<li>No Reflection: It&#8217;s slow I don&#8217;t want to have to use it when redirects happen often.</li>
<li>Parameters: I want to be able to pass parameters to a function and make that become part of the get request, I want the logic for that to exist on the page being redirected to as that is where the parameters are being used, this will also help with refactoring, the plain ole redirect logic however would just exist on a base class, don&#8217;t want to have to rewrite for every page.</li>
</ul>
<p>I knew the ideal situation would be if I could somehow use the fact that web application projects use the folder hierarchy for its namespace convention and end up being able to redirect to the page ~/Users/UserDetails.aspx?UserId=14 with the following command Users.UserDetails.Redirect(14);</p>
<p>Here is how I did it:<span id="more-249"></span></p>
<p>I have a web application project, let&#8217;s call it MyProject.Web</p>
<p>I have two pages called UserDetails.aspx and UserList.aspx in the folder Users.</p>
<p>They both inherit from the following base class:</p>
<div id="_mcePaste">
<blockquote>
<div id="_mcePaste">namespace MyProject.UI</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">/// &lt;summary&gt;</div>
<div id="_mcePaste">/// Summary description for BasePage</div>
<div id="_mcePaste">/// &lt;/summary&gt;</div>
<div id="_mcePaste">public abstract class BasePage&lt;T&gt;:Page where T : Page</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">public static String GetUrl()</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">return &#8220;~/&#8221; + typeof(T).ToString().Replace(&#8220;MyProject.Web.&#8221;, &#8220;&#8221;).Replace(&#8216;.&#8217;, &#8216;/&#8217;) + &#8220;.aspx&#8221;;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">public static String GetUrl(String parameters)</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">return GetUrl() + &#8220;?&#8221; + parameters;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">public static void Redirect()</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">HttpContext.Current.Response.Redirect(GetUrl());</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">public static void Redirect(String parameters)</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">HttpContext.Current.Response.Redirect(GetUrl(parameters));</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">public static void Redirect(Boolean endResponse)</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">HttpContext.Current.Response.Redirect(GetUrl(),endResponse);</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">public static void Redirect(String parameters,Boolean endResponse)</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">HttpContext.Current.Response.Redirect(GetUrl(parameters), endResponse);</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">}</div>
</blockquote>
</div>
<p>They follow this pattern:</p>
<blockquote><p>namespace MyProject.Web.Users</p>
<p>{</p>
<p><span style="white-space: pre;"> </span>public partial class UserDetails: BasePage&lt;UserDetails&gt;</p>
<p><span style="white-space: pre;"> </span>{</p>
<p><span style="white-space: pre;"> </span>public static void Redirect(int userId)</p>
<p><span style="white-space: pre;"> </span>{</p>
<p><span style="white-space: pre;"> </span>Redirect(&#8220;UserId=&#8221; + userId.ToString());</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span>}</p>
<p>}</p></blockquote>
<p>Now because UserDetails and UserList are in the same folder I can simply call UserDetails.Redirect(selectedUserId) on the UserList and UserList.Redirect() on the UserDetails.<br />
The only real disadvantage is that it could confuse people who discover a Redirect method on their current page that they can&#8217;t use to make it to another page.<br />
However it should be abundantly clear to everyone what you are doing when they see it already written.<br />
Also every time you move a class, remove or add a parameter, it will break on compile time not at run time.</p>
<p>Comments and feedback welcome.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.lacy.ie%2Fredirecting-using-strong-types-in-an-asp-net-web-application-project&amp;linkname=Redirecting%20using%20strong%20types%20in%20an%20asp.net%20web%20application%20project"><img src="http://www.lacy.ie/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>Related posts:<ol><li><a href='http://www.lacy.ie/how-to-mock-the-httpcontext-in-asp-net' rel='bookmark' title='Permanent Link: How to Mock the HttpContext in asp.net'>How to Mock the HttpContext in asp.net</a> <small>I find mocking the http context rather difficult, you can&#8217;t...</small></li>
<li><a href='http://www.lacy.ie/jquery-grid-plugin-jqgrid-with-asp-net-web-forms' rel='bookmark' title='Permanent Link: jQuery Grid Plugin (JqGrid) with ASP.Net Web Forms'>jQuery Grid Plugin (JqGrid) with ASP.Net Web Forms</a> <small>Get JqGrid here: http://www.trirand.com/blog/ So far I&#8217;ve seen two implementations...</small></li>
<li><a href='http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms' rel='bookmark' title='Permanent Link: Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms'>Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms</a> <small>I had a problem where I wanted to use the...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.lacy.ie/redirecting-using-strong-types-in-an-asp-net-web-application-project/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Grid Plugin (JqGrid) with ASP.Net Web Forms</title>
		<link>http://www.lacy.ie/jquery-grid-plugin-jqgrid-with-asp-net-web-forms</link>
		<comments>http://www.lacy.ie/jquery-grid-plugin-jqgrid-with-asp-net-web-forms#comments</comments>
		<pubDate>Mon, 24 Aug 2009 17:57:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[JqGrid]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Jquery UI]]></category>
		<category><![CDATA[Web Forms]]></category>

		<guid isPermaLink="false">http://lacy.ie/?p=162</guid>
		<description><![CDATA[Get JqGrid here: http://www.trirand.com/blog/ So far I&#8217;ve seen two implementations of ASP.Net wrapper on JqGrid, one involves a httphandler and the other involves using a web service. Both add extra work onto the gridview/datasource pattern. Instead I had the JqGrid use a Callback Event Reference (Page.ClientScript.GetCallbackEventReference()) with async (a parameter) set to true, this allowed [...]


Related posts:<ol><li><a href='http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms' rel='bookmark' title='Permanent Link: Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms'>Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms</a> <small>I had a problem where I wanted to use the...</small></li>
<li><a href='http://www.lacy.ie/cant-register-javascript-for-invisible-control' rel='bookmark' title='Permanent Link: Can&#039;t Register Javascript for Invisible Control'>Can&#039;t Register Javascript for Invisible Control</a> <small>I was writing an ASP.Net Dialog Control and I overwrote...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Get JqGrid here: <a href="http://www.trirand.com/blog/">http://www.trirand.com/blog/</a></p>
<p style="text-align: left;">So far I&#8217;ve seen two implementations of ASP.Net wrapper on JqGrid, one involves a httphandler and the other involves using a web service. Both add extra work onto the gridview/datasource pattern.</p>
<p style="text-align: left;">Instead I had the JqGrid use a Callback Event Reference (<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.getcallbackeventreference.aspx">Page.ClientScript.GetCallbackEventReference()</a>) with async (a parameter) set to true, this allowed me to call back directly to the custom asp.net JqGrid control instance and access the DataSource.</p>
<p style="text-align: left;">This is not ideal, as it passes the view state to the server first but it is the simplest and cleanest going from ASP.Net GridView to JqGrid.</p>
<p style="text-align: left;"><span id="more-162"></span></p>
<h2 style="text-align: left;">Other useful information</h2>
<p style="text-align: left;">Inherit CompositeDataBoundControl and add the attribute<br />
<span style="color: #3366ff;">[PersistenceModeAttribute(PersistenceMode.InnerProperty)]<br />
public DataControlFieldCollection Columns { get; set; }</span><br />
in order to get<br />
<span style="color: #3366ff;">&lt;My:Grid&gt;<br />
&lt;columns&gt;<br />
&lt;asp:BoundField&#8230;.</span><br />
working</p>
<p style="text-align: left;">implement CallbackEventHandler otherwise the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.getcallbackeventreference.aspx">Page.ClientScript.GetCallbackEventReference()</a> won&#8217;t work.</p>
<p style="text-align: left;">I&#8217;d recommend using Rick Strahl&#8217;s ClientScriptProxy for registering your Javascript, it solves the problem of whether the page your control ended up on has a scriptmanager. Find that here: <a href="http://www.west-wind.com/weblog/posts/10246.aspx">http://www.west-wind.com/weblog/posts/10246.aspx</a></p>
<p style="text-align: left;">Here are some pages I found helpful on JqGrid: (if I find any more I&#8217;ll add them)</p>
<p style="text-align: left;"><a href="http://www.nshaw.com/2009/01/jqgrid-and-aspnet-web-forms-with-json.html">http://www.nshaw.com/2009/01/jqgrid-and-aspnet-web-forms-with-json.html</a><br />
<a href="http://geeks.netindonesia.net/blogs/cipto/archive/2009/04/03/jqgrid.aspx">http://geeks.netindonesia.net/blogs/cipto/archive/2009/04/03/jqgrid.aspx</a><br />
<a href="http://www.codeproject.com/KB/WCF/jqGrid.aspx">http://www.codeproject.com/KB/WCF/jqGrid.aspx</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.lacy.ie%2Fjquery-grid-plugin-jqgrid-with-asp-net-web-forms&amp;linkname=jQuery%20Grid%20Plugin%20%28JqGrid%29%20with%20ASP.Net%20Web%20Forms"><img src="http://www.lacy.ie/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>Related posts:<ol><li><a href='http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms' rel='bookmark' title='Permanent Link: Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms'>Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms</a> <small>I had a problem where I wanted to use the...</small></li>
<li><a href='http://www.lacy.ie/cant-register-javascript-for-invisible-control' rel='bookmark' title='Permanent Link: Can&#039;t Register Javascript for Invisible Control'>Can&#039;t Register Javascript for Invisible Control</a> <small>I was writing an ASP.Net Dialog Control and I overwrote...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.lacy.ie/jquery-grid-plugin-jqgrid-with-asp-net-web-forms/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Can&#039;t Register Javascript for Invisible Control</title>
		<link>http://www.lacy.ie/cant-register-javascript-for-invisible-control</link>
		<comments>http://www.lacy.ie/cant-register-javascript-for-invisible-control#comments</comments>
		<pubDate>Wed, 19 Aug 2009 14:04:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Control Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Forms]]></category>

		<guid isPermaLink="false">http://lacy.ie/?p=157</guid>
		<description><![CDATA[I was writing an ASP.Net Dialog Control and I overwrote the Visible property to mean does the Dialog Control get displayed on the page initally, this defaulted to false. Later on I discovered that I couldn&#8217;t seem to register any javascript from the control. Turns out that it wasn&#8217;t being registered because of the lack [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I was writing an ASP.Net Dialog Control and I overwrote the Visible property to mean does the Dialog Control get displayed on the page initally, this defaulted to false.</p>
<p>Later on I discovered that I couldn&#8217;t seem to register any javascript from the control. Turns out that it wasn&#8217;t being registered because of the lack of visibility. .Net was treating it like an on/off switch even though I&#8217;d told it not to. It&#8217;s things like this that make me want to use ASP.Net MVC.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.lacy.ie%2Fcant-register-javascript-for-invisible-control&amp;linkname=Can%26%23039%3Bt%20Register%20Javascript%20for%20Invisible%20Control"><img src="http://www.lacy.ie/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.lacy.ie/cant-register-javascript-for-invisible-control/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling Relative Paths and debug mode with Jquery in ASP.Net Web Forms</title>
		<link>http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms</link>
		<comments>http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms#comments</comments>
		<pubDate>Wed, 12 Aug 2009 10:08:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Web Forms]]></category>

		<guid isPermaLink="false">http://lacy.ie/?p=153</guid>
		<description><![CDATA[I had a problem where I wanted to use the intellisense version of JQuery when I am writing the code, the normal version when I debug it and the minified when it actually hits production. I also wanted all this done on my master page so the path to the js file had to be [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I had a problem where I wanted to use the intellisense version of JQuery when I am writing the code, the normal version when I debug it and the minified when it actually hits production.<br />
I also wanted all this done on my master page so the path to the js file had to be relative to the site root and not the page it was defined on.</p>
<p>I found the solution here:</p>
<p><a href="http://damianedwards.wordpress.com/2009/03/28/setting-up-jquery-for-aspnet-web-forms-projects/">http://damianedwards.wordpress.com/2009/03/28/setting-up-jquery-for-aspnet-web-forms-projects/</a></p>
<p>It essentially revolves around using the script manager to reference the JS files and using naming conventions so it knows which one to open where.</p>
<p>Edit: <span style="color: #ff6600;">Don&#8217;t forget to download the hotfix or the -vsdoc won&#8217;t work.</span></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.lacy.ie%2Fhandling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms&amp;linkname=Handling%20Relative%20Paths%20and%20debug%20mode%20with%20Jquery%20in%20ASP.Net%20Web%20Forms"><img src="http://www.lacy.ie/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.lacy.ie/handling-relative-paths-and-debug-mode-with-jquery-in-asp-net-web-forms/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->