<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Dynamically Loading ASP.NET User Controls with jQuery</title>
	<atom:link href="http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/</link>
	<description>My thoughts, stuff I need to remember or things I just want to share with the world</description>
	<lastBuildDate>Thu, 02 Feb 2012 16:13:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Poul Bak</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-22</link>
		<dc:creator>Poul Bak</dc:creator>
		<pubDate>Wed, 04 Nov 2009 08:44:35 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-22</guid>
		<description>Instead of messing with custom attributes, you could simply use the following:

&lt;add verb=&quot;*&quot; path=&quot;*.ajax.ascx&quot; type=&quot;[NAMESPACE].AjaxUserControlHandler, [ASSEMBLY]&quot;/&gt;

Simply name your &#039;runnable&#039; usercontrols like that (with &#039;.ajax&#039; in name), works the same.</description>
		<content:encoded><![CDATA[<p>Instead of messing with custom attributes, you could simply use the following:</p>
<p>&lt;add verb=&quot;*&quot; path=&quot;*.ajax.ascx&quot; type=&quot;[NAMESPACE].AjaxUserControlHandler, [ASSEMBLY]&quot;/&gt;</p>
<p>Simply name your &#8216;runnable&#8217; usercontrols like that (with &#8216;.ajax&#8217; in name), works the same.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H.</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-21</link>
		<dc:creator>John H.</dc:creator>
		<pubDate>Fri, 09 Oct 2009 08:43:27 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-21</guid>
		<description>To run with localhost I made some changes...
      Default.aspx:
$(&quot;#datetime&quot;).load(&quot;Controls/Datetime.ascx&quot;);
$(&quot;#datetime&quot;).load(&quot;DateTimeServerControl.sch&quot;);
      AjaxServerControlHander:
string typeName = path.Substring(0, path.Length - 4); 
typeName = typeName.Substring(typeName.LastIndexOf(&#039;/&#039;) + 1);

It works great. Thanks Mikkel!</description>
		<content:encoded><![CDATA[<p>To run with localhost I made some changes&#8230;<br />
      Default.aspx:<br />
$(&quot;#datetime&quot;).load(&quot;Controls/Datetime.ascx&quot;);<br />
$(&quot;#datetime&quot;).load(&quot;DateTimeServerControl.sch&quot;);<br />
      AjaxServerControlHander:<br />
string typeName = path.Substring(0, path.Length &#8211; 4);<br />
typeName = typeName.Substring(typeName.LastIndexOf(&#8216;/&#8217;) + 1);</p>
<p>It works great. Thanks Mikkel!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wheels for sale</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-20</link>
		<dc:creator>wheels for sale</dc:creator>
		<pubDate>Tue, 29 Sep 2009 06:42:48 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-20</guid>
		<description>Great idea and I thank you for all that work, but your example is lacking how to implement it. Kind of like all the wheels and cogs are there, but the screws are missing. Please post a sample project? </description>
		<content:encoded><![CDATA[<p>Great idea and I thank you for all that work, but your example is lacking how to implement it. Kind of like all the wheels and cogs are there, but the screws are missing. Please post a sample project?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mikkel Ovesen</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-19</link>
		<dc:creator>Mikkel Ovesen</dc:creator>
		<pubDate>Thu, 16 Jul 2009 23:39:20 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-19</guid>
		<description>@rac: I have updated the source code to support async. calling of a WebControl. When using this approach, it is not possible to use the ViewState for these controls, and this excludes using some standard ASP.NET controls. If you want make use of the ViewState, it would be easier to just use Microsoft ASP.NET Ajax partial rendering.

@Steve: You are correct, the first version was coded quickly and only as a sample. But I have updated the sourcecode.</description>
		<content:encoded><![CDATA[<p>@rac: I have updated the source code to support async. calling of a WebControl. When using this approach, it is not possible to use the ViewState for these controls, and this excludes using some standard ASP.NET controls. If you want make use of the ViewState, it would be easier to just use Microsoft ASP.NET Ajax partial rendering.</p>
<p>@Steve: You are correct, the first version was coded quickly and only as a sample. But I have updated the sourcecode.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-18</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 16 Jul 2009 02:17:54 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-18</guid>
		<description>This is a pretty nice solution, but for a high usage app/website, I would recommend adding a using statement for the Page object. Not properly disposing of it could lead to some serious memory fragmentation and performance problems.</description>
		<content:encoded><![CDATA[<p>This is a pretty nice solution, but for a high usage app/website, I would recommend adding a using statement for the Page object. Not properly disposing of it could lead to some serious memory fragmentation and performance problems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rac</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-17</link>
		<dc:creator>rac</dc:creator>
		<pubDate>Sat, 13 Jun 2009 07:13:11 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-17</guid>
		<description>I am working using this and I was wondering if you were ever able to get this to work using server controls in your usercontrol. I am stuck trying to figure out how to dynamically override(if possible) the Page&#039;s VerifyRenderingInServerForm method. Is there a way to do this dynamically?</description>
		<content:encoded><![CDATA[<p>I am working using this and I was wondering if you were ever able to get this to work using server controls in your usercontrol. I am stuck trying to figure out how to dynamically override(if possible) the Page&#8217;s VerifyRenderingInServerForm method. Is there a way to do this dynamically?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mikkel Ovesen</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-16</link>
		<dc:creator>Mikkel Ovesen</dc:creator>
		<pubDate>Mon, 08 Jun 2009 19:50:34 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-16</guid>
		<description>Ok, I will be posting a sample website in just a few minutes.</description>
		<content:encoded><![CDATA[<p>Ok, I will be posting a sample website in just a few minutes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-15</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Sat, 06 Jun 2009 05:33:15 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-15</guid>
		<description>Great idea and I thank you for all that work, but your example is lacking how to implement it.  Kind of like all the wheels and cogs are there, but the screws are missing.  Please post a sample project?  thanks!</description>
		<content:encoded><![CDATA[<p>Great idea and I thank you for all that work, but your example is lacking how to implement it.  Kind of like all the wheels and cogs are there, but the screws are missing.  Please post a sample project?  thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mikkel Ovesen</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-14</link>
		<dc:creator>Mikkel Ovesen</dc:creator>
		<pubDate>Fri, 08 May 2009 05:00:08 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-14</guid>
		<description>Thank you Kyle for the copy-paste version.</description>
		<content:encoded><![CDATA[<p>Thank you Kyle for the copy-paste version.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Corley</title>
		<link>http://blog.ovesens.net/2008/12/dynamically-loading-asp-net-user-controls-with-jquery/comment-page-1/#comment-13</link>
		<dc:creator>Kyle Corley</dc:creator>
		<pubDate>Fri, 08 May 2009 03:16:51 +0000</pubDate>
		<guid isPermaLink="false">/post/2008/12/26/Dynamically-Loading-ASPNET-User-Controls-with-jQuery.aspx#comment-13</guid>
		<description>I went through the trouble of copying it for my own use, so here&#039;s a more copy-and-paste-friendly version of the source above.  Thanks again for the great ideas!
===========================================

public class AjaxUserControlHandler : IHttpHandler   
  {   
    public void ProcessRequest(HttpContext context)   
    {   
       // Get the path  to the user control   
       string path  = context.Request.Url.LocalPath;   

       // Intialize the pseudo  page and user control   
       Page page  = new Page();  
       UserControl viewControl = page.LoadControl(path) as UserControl;  

       // Display error if the user control was not found  
       if (viewControl == null)  
       {  
         context.Response.StatusCode = 404;  
         context.Response.Output.WriteLine(&quot;The requested url was not found&quot;);  
         return;  
       }   

       // Check existense of the AjaxEnabled attribute. Only add the AjaxEnabled attribut to   
       // user controls that is safe for direct calls  
       var type = viewControl.GetType();  
       var attributes = type.GetCustomAttributes(typeof (AjaxEnabledAttribute), true);  
       AjaxEnabledAttribute attribute = attributes.FirstOrDefault() as AjaxEnabledAttribute;  

       // If the attribute was not found, display an error  
       if (attribute == null)  
       {  
         context.Response.StatusCode = 403;  
         context.Response.Output.WriteLine(&quot;Access to the resource is not allowed&quot;);  
         return;  
       }  

         
       // Check if the request is valiud with regards to the requirements of the attribute.  
       // If not, display error  
       if ((attribute.Method == RequestMethodSupport.GET &amp;&amp; context.Request.RequestType != &quot;GET&quot;)  
          &#124;&#124;  (attribute.Method == RequestMethodSupport.POST &amp;&amp; context.Request.RequestType != &quot;POST&quot;))  
       {  
         context.Response.StatusCode = 403;  
         context.Response.Output.WriteLine(string.Format(&quot;The request method {0} is not allowed.&quot;, context.Request.RequestType));  
         return;  
       }  

       // Add user control to the pages control tree  
       page.Controls.Add(viewControl);  

       // Disable caching, remove this if you will allow client caching  
       context.Response.CacheControl = &quot;No-Cache&quot;;  

       // Execute and return result to Output stream  
       context.Server.Execute(page, context.Response.Output, true);  
     }  

     public bool IsReusable  
     {  
        get { return  true; }  
     }  
   }</description>
		<content:encoded><![CDATA[<p>I went through the trouble of copying it for my own use, so here&#8217;s a more copy-and-paste-friendly version of the source above.  Thanks again for the great ideas!<br />
===========================================</p>
<p>public class AjaxUserControlHandler : IHttpHandler<br />
  {<br />
    public void ProcessRequest(HttpContext context)<br />
    {<br />
       // Get the path  to the user control<br />
       string path  = context.Request.Url.LocalPath;   </p>
<p>       // Intialize the pseudo  page and user control<br />
       Page page  = new Page();<br />
       UserControl viewControl = page.LoadControl(path) as UserControl;  </p>
<p>       // Display error if the user control was not found<br />
       if (viewControl == null)<br />
       {<br />
         context.Response.StatusCode = 404;<br />
         context.Response.Output.WriteLine(&quot;The requested url was not found&quot;);<br />
         return;<br />
       }   </p>
<p>       // Check existense of the AjaxEnabled attribute. Only add the AjaxEnabled attribut to<br />
       // user controls that is safe for direct calls<br />
       var type = viewControl.GetType();<br />
       var attributes = type.GetCustomAttributes(typeof (AjaxEnabledAttribute), true);<br />
       AjaxEnabledAttribute attribute = attributes.FirstOrDefault() as AjaxEnabledAttribute;  </p>
<p>       // If the attribute was not found, display an error<br />
       if (attribute == null)<br />
       {<br />
         context.Response.StatusCode = 403;<br />
         context.Response.Output.WriteLine(&quot;Access to the resource is not allowed&quot;);<br />
         return;<br />
       }  </p>
<p>       // Check if the request is valiud with regards to the requirements of the attribute.<br />
       // If not, display error<br />
       if ((attribute.Method == RequestMethodSupport.GET &amp;&amp; context.Request.RequestType != &quot;GET&quot;)<br />
          ||  (attribute.Method == RequestMethodSupport.POST &amp;&amp; context.Request.RequestType != &quot;POST&quot;))<br />
       {<br />
         context.Response.StatusCode = 403;<br />
         context.Response.Output.WriteLine(string.Format(&quot;The request method {0} is not allowed.&quot;, context.Request.RequestType));<br />
         return;<br />
       }  </p>
<p>       // Add user control to the pages control tree<br />
       page.Controls.Add(viewControl);  </p>
<p>       // Disable caching, remove this if you will allow client caching<br />
       context.Response.CacheControl = &quot;No-Cache&quot;;  </p>
<p>       // Execute and return result to Output stream<br />
       context.Server.Execute(page, context.Response.Output, true);<br />
     }  </p>
<p>     public bool IsReusable<br />
     {<br />
        get { return  true; }<br />
     }<br />
   }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

