<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Rajan's Blog</title>
    <link>http://blog.rajan.net.in/</link>
    <description>Experience Talks</description>
    <language>en-us</language>
    <copyright>Rajan R.G</copyright>
    <lastBuildDate>Sat, 13 Feb 2010 19:22:31 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>rgrajan@gmail.com</managingEditor>
    <webMaster>rgrajan@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=3a795ab9-6785-4dd8-97d4-02e33bbd8153</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=3a795ab9-6785-4dd8-97d4-02e33bbd8153</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The important functionality of any ecommerce system is to transfer the content using
SSL when the user enters the user name &amp; password or while accepting the credit
card info. <a href="http://blog.stevensanderson.com/2008/08/05/adding-httpsssl-support-to-aspnet-mvc-routing/" target="_blank">Steve
Sanderson</a> has blogged about this and unfortunately it didn’t work for me. Also <a href="http://aspnet.codeplex.com/releases/view/24471" target="_blank">MVC
Futures</a> has RequiresSSL extension which transform the content to secure. But in
a typical system, we need to redirect back to HTTP as well, i.e if there is a booking
flow, after we get the credit card and validating the payment details, the confirmation
page might or should be in HTTP. 
</p>
        <p>
There are various solution available, i have decided to use the MVC Futures code and
slightly modify the same to implement this functionality. 
</p>
        <pre class="brush: csharp;">public sealed class SwitchSsl : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (!Enable)
            return;

        if (filterContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }
        if (!filterContext.HttpContext.Request.IsSecureConnection &amp;&amp; Mode==Protocol.https)
        {
            if (!this.Redirect)
            {
                throw new HttpException(0x193, "Must use SSL");
            }
            RedirectUrl(Protocol.https, filterContext);
        }
        else if (filterContext.HttpContext.Request.IsSecureConnection &amp;&amp; Mode==Protocol.http)
        {
            RedirectUrl(Protocol.http, filterContext);
        }
    }

    public bool Redirect { get; set; }

    public Protocol Mode { get; set; }

    public bool Enable
    {
        get {
            return Convert.ToBoolean(ConfigurationManager.AppSettings.Get("EnableSsl"));
        }
    }

    private void RedirectUrl(Protocol scheme, AuthorizationContext filterContext)
    {
        UriBuilder builder2 = new UriBuilder();
        builder2.Scheme = scheme.ToString();
        builder2.Host = filterContext.HttpContext.Request.Url.Host;
        builder2.Path = filterContext.HttpContext.Request.RawUrl;
        UriBuilder builder = builder2;
        filterContext.Result = new RedirectResult(builder.ToString());
    }

    public enum Protocol
    {
        http,
        https
    }

}</pre>
        <p>
Enable property is an optional configuration in the web.config, so that we can enable
this only in the production environment. And in the controller action,we can call
like below.
</p>
        <pre class="brush: csharp;">[SwitchSsl(Redirect = true, Mode=SwitchSsl.Protocol.https)]
public ActionResult Reserve()</pre>
        <p>
Happy Coding!
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=3a795ab9-6785-4dd8-97d4-02e33bbd8153" />
      </body>
      <title>ASP.NET MVC – Switch between secure(https or ssl) &amp; unsecure(http) connections</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</guid>
      <link>http://blog.rajan.net.in/2010/02/13/ASPNETMVCSwitchBetweenSecurehttpsOrSslUnsecurehttpConnections.aspx</link>
      <pubDate>Sat, 13 Feb 2010 19:22:31 GMT</pubDate>
      <description>&lt;p&gt;
The important functionality of any ecommerce system is to transfer the content using
SSL when the user enters the user name &amp;amp; password or while accepting the credit
card info. &lt;a href="http://blog.stevensanderson.com/2008/08/05/adding-httpsssl-support-to-aspnet-mvc-routing/" target="_blank"&gt;Steve
Sanderson&lt;/a&gt; has blogged about this and unfortunately it didn’t work for me. Also &lt;a href="http://aspnet.codeplex.com/releases/view/24471" target="_blank"&gt;MVC
Futures&lt;/a&gt; has RequiresSSL extension which transform the content to secure. But in
a typical system, we need to redirect back to HTTP as well, i.e if there is a booking
flow, after we get the credit card and validating the payment details, the confirmation
page might or should be in HTTP. 
&lt;/p&gt;
&lt;p&gt;
There are various solution available, i have decided to use the MVC Futures code and
slightly modify the same to implement this functionality. 
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public sealed class SwitchSsl : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (!Enable)
            return;

        if (filterContext == null)
        {
            throw new ArgumentNullException(&amp;quot;filterContext&amp;quot;);
        }
        if (!filterContext.HttpContext.Request.IsSecureConnection &amp;amp;&amp;amp; Mode==Protocol.https)
        {
            if (!this.Redirect)
            {
                throw new HttpException(0x193, &amp;quot;Must use SSL&amp;quot;);
            }
            RedirectUrl(Protocol.https, filterContext);
        }
        else if (filterContext.HttpContext.Request.IsSecureConnection &amp;amp;&amp;amp; Mode==Protocol.http)
        {
            RedirectUrl(Protocol.http, filterContext);
        }
    }

    public bool Redirect { get; set; }

    public Protocol Mode { get; set; }

    public bool Enable
    {
        get {
            return Convert.ToBoolean(ConfigurationManager.AppSettings.Get(&amp;quot;EnableSsl&amp;quot;));
        }
    }

    private void RedirectUrl(Protocol scheme, AuthorizationContext filterContext)
    {
        UriBuilder builder2 = new UriBuilder();
        builder2.Scheme = scheme.ToString();
        builder2.Host = filterContext.HttpContext.Request.Url.Host;
        builder2.Path = filterContext.HttpContext.Request.RawUrl;
        UriBuilder builder = builder2;
        filterContext.Result = new RedirectResult(builder.ToString());
    }

    public enum Protocol
    {
        http,
        https
    }

}&lt;/pre&gt;
&lt;p&gt;
Enable property is an optional configuration in the web.config, so that we can enable
this only in the production environment. And in the controller action,we can call
like below.
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;[SwitchSsl(Redirect = true, Mode=SwitchSsl.Protocol.https)]
public ActionResult Reserve()&lt;/pre&gt;
&lt;p&gt;
Happy Coding!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=3a795ab9-6785-4dd8-97d4-02e33bbd8153" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=26fc6121-f28c-487a-95e6-c36d290c628e</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=26fc6121-f28c-487a-95e6-c36d290c628e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It is important to have logging enabled in any production site which will be used
by the technical team to debug the issues or monitor the health of the site. We chose <a href="http://dotnetlog.theobjectguy.com/" target="_blank">BitFactory</a> logging
(Now the author is calling as Termite) to implement the logging in WCF Services, Business
Layer &amp; ASP.NET MVC Sites. 
</p>
        <p>
Why did we choose BitFactory?
</p>
        <ul>
          <li>
It is very easy to implement. 
</li>
          <li>
Absolutely working with complex categories (we have 43 projects in a solution with
more than 25 categories configured for logging) 
</li>
          <li>
No issue with Multithreading or Filelocking issue. 
</li>
        </ul>
        <p>
I have used Nlog, Log4net, MS Enterprise library &amp; Elmah in various projects,
somehow my choice at this time is BitFactory. Other frameworks are good on their own
flavor and i am not against any frameworks whether it is commercial or open source.
</p>
        <p>
In ASP.NET MVC we have to use HandleError attribute to redirect to the customized
error page and i would like to implement the logging using the same attribute. Thanks
to <a href="http://blog.ploeh.dk/2009/12/07/LoggingExceptionFilter.aspx" target="_blank">Mark
Seemann</a> for the poor man’s Dependency Injection for the logging. I used the same
snippet but tried to integrate BitFactory logging. 
</p>
        <p>
ErrorHandlingActionInvoker.cs
</p>
        <pre class="brush: csharp;">public class ErrorHandlingActionInvoker : ControllerActionInvoker
{
    private readonly IExceptionFilter filter;

    public ErrorHandlingActionInvoker(IExceptionFilter filter)
    {
        if (filter == null)
        {
            throw new ArgumentNullException("filter");
        }
        
        this.filter = filter;
    }

    protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        var filterInfo =base.GetFilters(controllerContext, actionDescriptor);
        filterInfo.ExceptionFilters.Add(this.filter);
        return filterInfo;
    }

}</pre>
        <p>
ErrorHandlingControllerFactory.cs
</p>
        <pre class="brush: csharp;">public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
    public override IController CreateController(RequestContext requestContext,string controllerName)
    {
        var controller =base.CreateController(requestContext,controllerName);
        var c = controller as Controller;
        if (c != null)
        {
            c.ActionInvoker = new ErrorHandlingActionInvoker(new LoggingExceptionFilter(new HandleErrorAttribute()));
        }
        return controller;
    }

}</pre>
        <p>
LoggingExceptionFilter.cs
</p>
        <pre class="brush: csharp;">public class LoggingExceptionFilter : IExceptionFilter
{
    private readonly IExceptionFilter filter;
    private readonly ConfigLogger logWriter = ConfigLogger.Instance;

    public LoggingExceptionFilter(IExceptionFilter filter) 
    { 
        if (filter == null) 
        { 
            throw new ArgumentNullException("filter"); 
        } 
        if (logWriter == null) 
        { 
            throw new ArgumentNullException("logWriter"); 
        } 
        this.filter = filter; 
    }

    public void OnException(ExceptionContext filterContext)
    {
        this.logWriter.LogError(filterContext.Exception);
        this.filter.OnException(filterContext);
    }
}</pre>
        <p>
Web.Config
</p>
        <pre class="brush: xml;">&lt;BitFactory.Logging name="global" xmlns="http://BitFactory.Logging"&gt;
  &lt;rollingDateFileLoggers&gt;
    &lt;rollingDateFileLogger isEnabled="true" name="FrontEndLogger" formattedFileName="C:\Logs\services_{timestamp:yyyyMMdd}.log"/&gt;
  &lt;/rollingDateFileLoggers&gt;
&lt;/BitFactory.Logging&gt;</pre>
        <p>
Add this line in Global.asax.cs
</p>
        <pre class="brush: csharp;">ControllerBuilder.Current.SetControllerFactory(new ErrorHandlingControllerFactory());</pre>
        <p>
Happy Coding!
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=26fc6121-f28c-487a-95e6-c36d290c628e" />
      </body>
      <title>Using BitFactory logging in ASP.NET MVC HandleError</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</guid>
      <link>http://blog.rajan.net.in/2009/12/20/UsingBitFactoryLoggingInASPNETMVCHandleError.aspx</link>
      <pubDate>Sun, 20 Dec 2009 17:16:53 GMT</pubDate>
      <description>&lt;p&gt;
It is important to have logging enabled in any production site which will be used
by the technical team to debug the issues or monitor the health of the site. We chose &lt;a href="http://dotnetlog.theobjectguy.com/" target="_blank"&gt;BitFactory&lt;/a&gt; logging
(Now the author is calling as Termite) to implement the logging in WCF Services, Business
Layer &amp;amp; ASP.NET MVC Sites. 
&lt;/p&gt;
&lt;p&gt;
Why did we choose BitFactory?
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
It is very easy to implement. 
&lt;/li&gt;
&lt;li&gt;
Absolutely working with complex categories (we have 43 projects in a solution with
more than 25 categories configured for logging) 
&lt;/li&gt;
&lt;li&gt;
No issue with Multithreading or Filelocking issue. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I have used Nlog, Log4net, MS Enterprise library &amp;amp; Elmah in various projects,
somehow my choice at this time is BitFactory. Other frameworks are good on their own
flavor and i am not against any frameworks whether it is commercial or open source.
&lt;/p&gt;
&lt;p&gt;
In ASP.NET MVC we have to use HandleError attribute to redirect to the customized
error page and i would like to implement the logging using the same attribute. Thanks
to &lt;a href="http://blog.ploeh.dk/2009/12/07/LoggingExceptionFilter.aspx" target="_blank"&gt;Mark
Seemann&lt;/a&gt; for the poor man’s Dependency Injection for the logging. I used the same
snippet but tried to integrate BitFactory logging. 
&lt;/p&gt;
&lt;p&gt;
ErrorHandlingActionInvoker.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class ErrorHandlingActionInvoker : ControllerActionInvoker
{
    private readonly IExceptionFilter filter;

    public ErrorHandlingActionInvoker(IExceptionFilter filter)
    {
        if (filter == null)
        {
            throw new ArgumentNullException(&amp;quot;filter&amp;quot;);
        }
        
        this.filter = filter;
    }

    protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        var filterInfo =base.GetFilters(controllerContext, actionDescriptor);
        filterInfo.ExceptionFilters.Add(this.filter);
        return filterInfo;
    }

}&lt;/pre&gt;
&lt;p&gt;
ErrorHandlingControllerFactory.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
    public override IController CreateController(RequestContext requestContext,string controllerName)
    {
        var controller =base.CreateController(requestContext,controllerName);
        var c = controller as Controller;
        if (c != null)
        {
            c.ActionInvoker = new ErrorHandlingActionInvoker(new LoggingExceptionFilter(new HandleErrorAttribute()));
        }
        return controller;
    }

}&lt;/pre&gt;
&lt;p&gt;
LoggingExceptionFilter.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class LoggingExceptionFilter : IExceptionFilter
{
    private readonly IExceptionFilter filter;
    private readonly ConfigLogger logWriter = ConfigLogger.Instance;

    public LoggingExceptionFilter(IExceptionFilter filter) 
    { 
        if (filter == null) 
        { 
            throw new ArgumentNullException(&amp;quot;filter&amp;quot;); 
        } 
        if (logWriter == null) 
        { 
            throw new ArgumentNullException(&amp;quot;logWriter&amp;quot;); 
        } 
        this.filter = filter; 
    }

    public void OnException(ExceptionContext filterContext)
    {
        this.logWriter.LogError(filterContext.Exception);
        this.filter.OnException(filterContext);
    }
}&lt;/pre&gt;
&lt;p&gt;
Web.Config
&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;BitFactory.Logging name=&amp;quot;global&amp;quot; xmlns=&amp;quot;http://BitFactory.Logging&amp;quot;&amp;gt;
  &amp;lt;rollingDateFileLoggers&amp;gt;
    &amp;lt;rollingDateFileLogger isEnabled=&amp;quot;true&amp;quot; name=&amp;quot;FrontEndLogger&amp;quot; formattedFileName=&amp;quot;C:\Logs\services_{timestamp:yyyyMMdd}.log&amp;quot;/&amp;gt;
  &amp;lt;/rollingDateFileLoggers&amp;gt;
&amp;lt;/BitFactory.Logging&amp;gt;&lt;/pre&gt;
&lt;p&gt;
Add this line in Global.asax.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;ControllerBuilder.Current.SetControllerFactory(new ErrorHandlingControllerFactory());&lt;/pre&gt;
&lt;p&gt;
Happy Coding!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=26fc6121-f28c-487a-95e6-c36d290c628e" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=efa59e37-6e16-4834-972d-9d4c8d003792</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=efa59e37-6e16-4834-972d-9d4c8d003792</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In my current project I need to load the user control dynamically without post back.
After some googling found couple of posts which converts the partial view as string.
The issue here is it doesn’t support viewcontext, in my case i have custom view engine
which implements localization. Earlier i have gone through this useful <a href="http://elijahmanor.com/webdevdotnet/post/ASPNET-MVC-Cheat-Sheets.aspx" target="_blank">cheat
sheet</a>. Below is the simple implementation which works with custom view engine
and view context.
</p>
        <pre class="brush: csharp;">[AcceptVerbs(HttpVerbs.Get)]
public ActionResult LoadTopDestinations()
{
    return PartialView("TopDestinations");
}</pre>
        <p>
And this is how i call the controller from the javascript using jquery post.
</p>
        <pre class="brush: js;">function TopDestinationClick() {
    proxy.invoke("/Home/LoadTopDestinations", "", TopDestinationCallback, OnError);

}</pre>
        <p>
Thanks to Rick Strahl for the easy service proxy for jquery post.
</p>
        <pre class="brush: js;">function serviceProxy(serviceUrl)
{
    var _I = this;
    this.serviceUrl = serviceUrl;
    
    // *** Call a wrapped object
    this.invoke = function(method, data, callback, error) {
        // *** The service endpoint URL        
        var url = _I.serviceUrl + method;
        //alert(url);
        $.ajax({
            url: url,
            data: '',
            type: "GET",
            contentType: "html",
            timeout: 10000,
            success: callback,
            error: OnError
        });
    }
}

// *** Create a static instance
var serviceUrl = "";
var proxy = new serviceProxy(serviceUrl);</pre>
        <p>
And the callback event, just use jquery.html() method to load the partial view result.
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=efa59e37-6e16-4834-972d-9d4c8d003792" />
      </body>
      <title>How to load partial view dynamically in ASP.NET MVC using JQuery</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</guid>
      <link>http://blog.rajan.net.in/2009/11/21/HowToLoadPartialViewDynamicallyInASPNETMVCUsingJQuery.aspx</link>
      <pubDate>Sat, 21 Nov 2009 21:38:45 GMT</pubDate>
      <description>&lt;p&gt;
In my current project I need to load the user control dynamically without post back.
After some googling found couple of posts which converts the partial view as string.
The issue here is it doesn’t support viewcontext, in my case i have custom view engine
which implements localization. Earlier i have gone through this useful &lt;a href="http://elijahmanor.com/webdevdotnet/post/ASPNET-MVC-Cheat-Sheets.aspx" target="_blank"&gt;cheat
sheet&lt;/a&gt;. Below is the simple implementation which works with custom view engine
and view context.
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;[AcceptVerbs(HttpVerbs.Get)]
public ActionResult LoadTopDestinations()
{
    return PartialView(&amp;quot;TopDestinations&amp;quot;);
}&lt;/pre&gt;
&lt;p&gt;
And this is how i call the controller from the javascript using jquery post.
&lt;/p&gt;
&lt;pre class="brush: js;"&gt;function TopDestinationClick() {
    proxy.invoke(&amp;quot;/Home/LoadTopDestinations&amp;quot;, &amp;quot;&amp;quot;, TopDestinationCallback, OnError);

}&lt;/pre&gt;
&lt;p&gt;
Thanks to Rick Strahl for the easy service proxy for jquery post.
&lt;/p&gt;
&lt;pre class="brush: js;"&gt;function serviceProxy(serviceUrl)
{
    var _I = this;
    this.serviceUrl = serviceUrl;
    
    // *** Call a wrapped object
    this.invoke = function(method, data, callback, error) {
        // *** The service endpoint URL        
        var url = _I.serviceUrl + method;
        //alert(url);
        $.ajax({
            url: url,
            data: '',
            type: &amp;quot;GET&amp;quot;,
            contentType: &amp;quot;html&amp;quot;,
            timeout: 10000,
            success: callback,
            error: OnError
        });
    }
}

// *** Create a static instance
var serviceUrl = &amp;quot;&amp;quot;;
var proxy = new serviceProxy(serviceUrl);&lt;/pre&gt;
&lt;p&gt;
And the callback event, just use jquery.html() method to load the partial view result.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=efa59e37-6e16-4834-972d-9d4c8d003792" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=38a093c5-5a49-4d7a-99d9-c6427d09daa8</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,38a093c5-5a49-4d7a-99d9-c6427d09daa8.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,38a093c5-5a49-4d7a-99d9-c6427d09daa8.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=38a093c5-5a49-4d7a-99d9-c6427d09daa8</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I hope the .NET developers are enjoying with C# 3.0 lambda expressions. This is one
of the easiest way for removing items from the generic list object based on a condition.
</p>
        <p>
_sessionList.RemoveAll(x =&gt; x.MarkforRemoval == true);
</p>
        <p>
The above code removes all the items marked for removal. This also avoid the error
“Collection was modified; enumeration operation may not execute” if you are checking
the conditions in the foreach loop and removing it.
</p>
        <p>
Quick snippet, hopefully useful.
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=38a093c5-5a49-4d7a-99d9-c6427d09daa8" />
      </body>
      <title>How to Remove items from generic List with condition</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,38a093c5-5a49-4d7a-99d9-c6427d09daa8.aspx</guid>
      <link>http://blog.rajan.net.in/2009/10/02/HowToRemoveItemsFromGenericListWithCondition.aspx</link>
      <pubDate>Fri, 02 Oct 2009 13:49:13 GMT</pubDate>
      <description>&lt;p&gt;
I hope the .NET developers are enjoying with C# 3.0 lambda expressions. This is one
of the easiest way for removing items from the generic list object based on a condition.
&lt;/p&gt;
&lt;p&gt;
_sessionList.RemoveAll(x =&amp;gt; x.MarkforRemoval == true);
&lt;/p&gt;
&lt;p&gt;
The above code removes all the items marked for removal. This also avoid the error
“Collection was modified; enumeration operation may not execute” if you are checking
the conditions in the foreach loop and removing it.
&lt;/p&gt;
&lt;p&gt;
Quick snippet, hopefully useful.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=38a093c5-5a49-4d7a-99d9-c6427d09daa8" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,38a093c5-5a49-4d7a-99d9-c6427d09daa8.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=06b3a7f2-079e-411a-99f4-0c06012b3f1d</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=06b3a7f2-079e-411a-99f4-0c06012b3f1d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We used to bind model class in ASP.NET MVC dropdownlist like below
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:08f84aed-8b0a-42a0-91f0-8a85e079aee4" class="wlWriterEditableSmartContent">
          <pre name="code" class="xml">&lt;%= Html.DropDownList("ApprovalStatus", Model.ApprovalStatus, new { @class = "select", onchange = "javascript:CheckApprovalStatus(this);" })%&gt;</pre>
        </div>
        <p>
The HTML output of the above is
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:9f2d86d5-ff23-41e0-b9d0-d413521a650f" class="wlWriterEditableSmartContent">
          <pre name="code" class="xml">&lt;select class="select" id="ApprovalStatus" name="ApprovalStatus" &gt;
&lt;option value="Approved"&gt;Approved&lt;/option&gt;
&lt;option value="Rejected"&gt;Rejected&lt;/option&gt;
&lt;option value="InProgress"&gt;In Progress&lt;/option&gt;
&lt;/select&gt;
</pre>
        </div>
        <p>
What if you would like to have Keys &amp; Value separately and like below and if the
model class is KeyValuePair
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:66df720f-2d17-4f72-904c-e3371e6facb8" class="wlWriterEditableSmartContent">
          <pre name="code" class="xml">&lt;select class="select" id="Country" name="Country"&gt;
&lt;option value="US"&gt;United States&lt;/option&gt;
&lt;option value="IN"&gt;India&lt;/option&gt;
&lt;option value="SG"&gt;Singapore&lt;/option&gt;
&lt;/select&gt;</pre>
        </div>
        <p>
then it should bind with Keys &amp; Values.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ef896479-82af-4d2a-aab0-69a9a667a56e" class="wlWriterEditableSmartContent">
          <pre name="code" class="c#">CountryList = new SelectList(Country.ToList(),"Key","Value");</pre>
        </div>
        <p>
Happy Coding!
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=06b3a7f2-079e-411a-99f4-0c06012b3f1d" />
      </body>
      <title>Bind KeyValuePair class to ASP.NET MVC HTML DropDownList</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</guid>
      <link>http://blog.rajan.net.in/2009/07/26/BindKeyValuePairClassToASPNETMVCHTMLDropDownList.aspx</link>
      <pubDate>Sun, 26 Jul 2009 05:30:00 GMT</pubDate>
      <description>&lt;p&gt;
We used to bind model class in ASP.NET MVC dropdownlist like below
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:08f84aed-8b0a-42a0-91f0-8a85e079aee4" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;%= Html.DropDownList("ApprovalStatus", Model.ApprovalStatus, new { @class = "select", onchange = "javascript:CheckApprovalStatus(this);" })%&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
The HTML output of the above is
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:9f2d86d5-ff23-41e0-b9d0-d413521a650f" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;select class="select" id="ApprovalStatus" name="ApprovalStatus" &amp;gt;
&amp;lt;option value="Approved"&amp;gt;Approved&amp;lt;/option&amp;gt;
&amp;lt;option value="Rejected"&amp;gt;Rejected&amp;lt;/option&amp;gt;
&amp;lt;option value="InProgress"&amp;gt;In Progress&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
What if you would like to have Keys &amp;amp; Value separately and like below and if the
model class is KeyValuePair
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:66df720f-2d17-4f72-904c-e3371e6facb8" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;select class="select" id="Country" name="Country"&amp;gt;
&amp;lt;option value="US"&amp;gt;United States&amp;lt;/option&amp;gt;
&amp;lt;option value="IN"&amp;gt;India&amp;lt;/option&amp;gt;
&amp;lt;option value="SG"&amp;gt;Singapore&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
then it should bind with Keys &amp;amp; Values.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ef896479-82af-4d2a-aab0-69a9a667a56e" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;CountryList = new SelectList(Country.ToList(),"Key","Value");&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Happy Coding!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=06b3a7f2-079e-411a-99f4-0c06012b3f1d" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=43ef0f23-32fa-4858-ae8b-f4d70e1ec911</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,43ef0f23-32fa-4858-ae8b-f4d70e1ec911.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,43ef0f23-32fa-4858-ae8b-f4d70e1ec911.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=43ef0f23-32fa-4858-ae8b-f4d70e1ec911</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It is very easy to format the datetime to string in .NET and this is commonly used
by the developers while displaying the date &amp; time in desired format. But if you
would like to store the formatted value in datetime variable, the value changes according
to the .NET default format.
</p>
        <p>
Default datetime format in .NET is
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_thumb_1.png" width="244" height="43" />
          </a>
        </p>
        <p>
We will try this to format the value,
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_thumb_2.png" width="244" height="34" />
          </a>
        </p>
        <p>
When we try to assign the formatted value to a datetime variable the format again
changed to default format
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_thumb_3.png" width="244" height="40" />
          </a>
        </p>
        <p>
To avoid this, use DateTime.ParseExact
</p>
        <pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;">DateTime dt = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);</pre>
        <p>
Where is this useful? 
<br />
If you develop client server application the .NET stores the datetime value with timezone.
The above syntax is timezone free, which will be useful across the application.
</p>
        <p>
Also refer this link for DateTime best practices <a title="http://msdn.microsoft.com/en-us/library/ms973825.aspx" href="http://msdn.microsoft.com/en-us/library/ms973825.aspx">http://msdn.microsoft.com/en-us/library/ms973825.aspx</a></p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=43ef0f23-32fa-4858-ae8b-f4d70e1ec911" />
      </body>
      <title>C#.NET How to format datetime and store in datetime variable</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,43ef0f23-32fa-4858-ae8b-f4d70e1ec911.aspx</guid>
      <link>http://blog.rajan.net.in/2009/05/01/CNETHowToFormatDatetimeAndStoreInDatetimeVariable.aspx</link>
      <pubDate>Fri, 01 May 2009 06:07:10 GMT</pubDate>
      <description>&lt;p&gt;
It is very easy to format the datetime to string in .NET and this is commonly used
by the developers while displaying the date &amp;amp; time in desired format. But if you
would like to store the formatted value in datetime variable, the value changes according
to the .NET default format.
&lt;/p&gt;
&lt;p&gt;
Default datetime format in .NET is
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_thumb_1.png" width="244" height="43" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
We will try this to format the value,
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_thumb_2.png" width="244" height="34" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
When we try to assign the formatted value to a datetime variable the format again
changed to default format
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/C.NETHowtoformatdatetimeandstoreindateti_A35B/image_thumb_3.png" width="244" height="40" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
To avoid this, use DateTime.ParseExact
&lt;/p&gt;
&lt;pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;"&gt;DateTime dt = DateTime.ParseExact(DateTime.Now.ToString(&amp;quot;yyyy-MM-dd HH:mm:ss.fff&amp;quot;), &amp;quot;yyyy-MM-dd HH:mm:ss.fff&amp;quot;, CultureInfo.InvariantCulture);&lt;/pre&gt;
&lt;p&gt;
Where is this useful? 
&lt;br /&gt;
If you develop client server application the .NET stores the datetime value with timezone.
The above syntax is timezone free, which will be useful across the application.
&lt;/p&gt;
&lt;p&gt;
Also refer this link for DateTime best practices &lt;a title="http://msdn.microsoft.com/en-us/library/ms973825.aspx" href="http://msdn.microsoft.com/en-us/library/ms973825.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms973825.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=43ef0f23-32fa-4858-ae8b-f4d70e1ec911" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,43ef0f23-32fa-4858-ae8b-f4d70e1ec911.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=60c04db3-7c93-4814-a793-dd1094469b0d</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,60c04db3-7c93-4814-a793-dd1094469b0d.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,60c04db3-7c93-4814-a793-dd1094469b0d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=60c04db3-7c93-4814-a793-dd1094469b0d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When there is nested master pages and when we try to access the control inside the
base master page, you will get an error "NullReferenceException". The reason is ASP.NET
didn't have the method to find the control in recursive.
</p>
        <p>
To explain in detail, we have BaseMaster.master file
</p>
        <pre class="brush: xml; ruler: true; gutter: false; auto-links: false;">&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="BaseMaster.master.cs" Inherits="MasterPage" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;XTP Site Manager&lt;/title&gt;
    &lt;asp:ContentPlaceHolder id="head" runat="server"&gt;&lt;/asp:ContentPlaceHolder&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div id="div_body"&gt;
        &lt;asp:ContentPlaceHolder id="body" runat="server"&gt;
        &lt;/asp:ContentPlaceHolder&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
        <p>
        </p>
        <p>
Another Master file which inherits BaseMaster, HomeMaster.master
</p>
        <pre class="brush: xml; ruler: true; gutter: false; auto-links: false;">&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="HomeMaster.master.cs" Inherits="MasterPages_HomeMaster" MasterPageFile="~/MasterPages/BaseMaster.master" %&gt;
&lt;asp:Content runat="server" ID="Content1" ContentPlaceHolderID="body"&gt;
             
        &lt;!-- HEADER --&gt;
        &lt;div id="div_header" runat="server" style="position: absolute; top: 0px; left: 0px; width: 900px; height: 100px"&gt;
            &lt;asp:contentplaceholder id="Header" runat="server"&gt;
            &lt;/asp:contentplaceholder&gt;
          &lt;/div&gt;
        
        &lt;!-- LEFT NAV --&gt;
        &lt;div id="div_leftnav" runat="server" style="position: absolute; top: 100px; left: 0px; width: 200px; height: 500px"&gt;
            &lt;asp:contentplaceholder id="LeftNav" runat="server"&gt;
            &lt;/asp:contentplaceholder&gt;

        &lt;/div&gt;
        
        &lt;!-- CENTER CONTENT --&gt;
        &lt;div id="div_content"  runat="server" style="position: absolute; top: 100px; left: 200px; width: 550px; height: 500px"&gt;
            &lt;asp:contentplaceholder id="Center" runat="server"&gt;
            &lt;/asp:contentplaceholder&gt;

        &lt;/div&gt;
        
        &lt;!-- RIGHT NAV --&gt;
        &lt;div id="div_rightnav" runat="server" style="position: absolute; top: 100px; left: 750px; width: 150px; height: 500px;"&gt;
            &lt;asp:contentplaceholder id="RightNav" runat="server"&gt;
            &lt;/asp:contentplaceholder&gt;

        &lt;/div&gt;
        
        &lt;!-- FOOTER --&gt;
        &lt;div id="div_footer" runat="server" style="position: absolute; top: 600px; left: 0px; width: 900px; height: 100px;"&gt;
            &lt;asp:contentplaceholder id="Footer" runat="server"&gt;
            &lt;/asp:contentplaceholder&gt;
        &lt;/div&gt;             
  
&lt;/asp:Content&gt; 
</pre>
        <p>
Now we have default page which inherits HomeMaster.master and in the codebehind we
will try to add an user control to the master page.
</p>
        <pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;">ContentPlaceHolder cp = new ContentPlaceHolder();
cp = Page.FindControl("Header") as ContentPlaceHolder;
if (cp != null)
{
    UserControl uc = this.LoadControl("usercontrols/static_widget.ascx") as UserControl;
    cp.Controls.Add(uc);
}
</pre>When
you try the above, you will get an error "NullRefernceException" is because of nested
master pages. Thanks to <a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx" target="_blank">C#
3.0 extensions</a>, in which we can extend the methods and it will be displayed in
VS Intellisense also.<pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;">public static class PageExtensionMethods
{
    public static Control FindControlRecursive(this Control ctrl, string controlID)
    {
        if (string.Compare(ctrl.ID, controlID, true) == 0)
        {
            // We found the control!
            return ctrl;
        }
        else
        {
            // Recurse through ctrl's Controls collections
            foreach (Control child in ctrl.Controls)
            {
                Control lookFor = FindControlRecursive(child, controlID);

                if (lookFor != null)
                    return lookFor;     // We found the control
            }

            // If we reach here, control was not found
            return null;
        }
    }
}
</pre>Now
you get another method "FindRecursiveControl" for the page, and the below code works
without any error. <pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;">ContentPlaceHolder cp = new ContentPlaceHolder();
cp = Page.FindControlRecursive("Header") as ContentPlaceHolder;
if (cp != null)
{
    UserControl uc = this.LoadControl("usercontrols/static_widget.ascx") as UserControl;
    cp.Controls.Add(uc);
}
</pre>Hope
this helps.
<img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=60c04db3-7c93-4814-a793-dd1094469b0d" /></body>
      <title>ASP.NET Nested Master Pages and Null Reference exception</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,60c04db3-7c93-4814-a793-dd1094469b0d.aspx</guid>
      <link>http://blog.rajan.net.in/2009/04/11/ASPNETNestedMasterPagesAndNullReferenceException.aspx</link>
      <pubDate>Sat, 11 Apr 2009 03:16:57 GMT</pubDate>
      <description>&lt;p&gt;
When there is nested master pages and when we try to access the control inside the
base master page, you will get an error "NullReferenceException". The reason is ASP.NET
didn't have the method to find the control in recursive.
&lt;/p&gt;
&lt;p&gt;
To explain in detail, we have BaseMaster.master file
&lt;/p&gt;
&lt;pre class="brush: xml; ruler: true; gutter: false; auto-links: false;"&gt;&amp;lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="BaseMaster.master.cs" Inherits="MasterPage" %&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head runat="server"&amp;gt;
    &amp;lt;title&amp;gt;XTP Site Manager&amp;lt;/title&amp;gt;
    &amp;lt;asp:ContentPlaceHolder id="head" runat="server"&amp;gt;&amp;lt;/asp:ContentPlaceHolder&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;form id="form1" runat="server"&amp;gt;
    &amp;lt;div id="div_body"&amp;gt;
        &amp;lt;asp:ContentPlaceHolder id="body" runat="server"&amp;gt;
        &amp;lt;/asp:ContentPlaceHolder&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Another Master file which inherits BaseMaster, HomeMaster.master
&lt;/p&gt;
&lt;pre class="brush: xml; ruler: true; gutter: false; auto-links: false;"&gt;&amp;lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="HomeMaster.master.cs" Inherits="MasterPages_HomeMaster" MasterPageFile="~/MasterPages/BaseMaster.master" %&amp;gt;
&amp;lt;asp:Content runat="server" ID="Content1" ContentPlaceHolderID="body"&amp;gt;
             
        &amp;lt;!-- HEADER --&amp;gt;
        &amp;lt;div id="div_header" runat="server" style="position: absolute; top: 0px; left: 0px; width: 900px; height: 100px"&amp;gt;
            &amp;lt;asp:contentplaceholder id="Header" runat="server"&amp;gt;
            &amp;lt;/asp:contentplaceholder&amp;gt;
          &amp;lt;/div&amp;gt;
        
        &amp;lt;!-- LEFT NAV --&amp;gt;
        &amp;lt;div id="div_leftnav" runat="server" style="position: absolute; top: 100px; left: 0px; width: 200px; height: 500px"&amp;gt;
            &amp;lt;asp:contentplaceholder id="LeftNav" runat="server"&amp;gt;
            &amp;lt;/asp:contentplaceholder&amp;gt;

        &amp;lt;/div&amp;gt;
        
        &amp;lt;!-- CENTER CONTENT --&amp;gt;
        &amp;lt;div id="div_content"  runat="server" style="position: absolute; top: 100px; left: 200px; width: 550px; height: 500px"&amp;gt;
            &amp;lt;asp:contentplaceholder id="Center" runat="server"&amp;gt;
            &amp;lt;/asp:contentplaceholder&amp;gt;

        &amp;lt;/div&amp;gt;
        
        &amp;lt;!-- RIGHT NAV --&amp;gt;
        &amp;lt;div id="div_rightnav" runat="server" style="position: absolute; top: 100px; left: 750px; width: 150px; height: 500px;"&amp;gt;
            &amp;lt;asp:contentplaceholder id="RightNav" runat="server"&amp;gt;
            &amp;lt;/asp:contentplaceholder&amp;gt;

        &amp;lt;/div&amp;gt;
        
        &amp;lt;!-- FOOTER --&amp;gt;
        &amp;lt;div id="div_footer" runat="server" style="position: absolute; top: 600px; left: 0px; width: 900px; height: 100px;"&amp;gt;
            &amp;lt;asp:contentplaceholder id="Footer" runat="server"&amp;gt;
            &amp;lt;/asp:contentplaceholder&amp;gt;
        &amp;lt;/div&amp;gt;             
  
&amp;lt;/asp:Content&amp;gt; 
&lt;/pre&gt;
&lt;p&gt;
Now we have default page which inherits HomeMaster.master and in the codebehind we
will try to add an user control to the master page.
&lt;/p&gt;
&lt;pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;"&gt;ContentPlaceHolder cp = new ContentPlaceHolder();
cp = Page.FindControl("Header") as ContentPlaceHolder;
if (cp != null)
{
    UserControl uc = this.LoadControl("usercontrols/static_widget.ascx") as UserControl;
    cp.Controls.Add(uc);
}
&lt;/pre&gt;When
you try the above, you will get an error "NullRefernceException" is because of nested
master pages. Thanks to &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx" target="_blank"&gt;C#
3.0 extensions&lt;/a&gt;, in which we can extend the methods and it will be displayed in
VS Intellisense also.&lt;pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;"&gt;public static class PageExtensionMethods
{
    public static Control FindControlRecursive(this Control ctrl, string controlID)
    {
        if (string.Compare(ctrl.ID, controlID, true) == 0)
        {
            // We found the control!
            return ctrl;
        }
        else
        {
            // Recurse through ctrl's Controls collections
            foreach (Control child in ctrl.Controls)
            {
                Control lookFor = FindControlRecursive(child, controlID);

                if (lookFor != null)
                    return lookFor;     // We found the control
            }

            // If we reach here, control was not found
            return null;
        }
    }
}
&lt;/pre&gt;Now
you get another method "FindRecursiveControl" for the page, and the below code works
without any error. &lt;pre class="brush: csharp; ruler: true; gutter: false; auto-links: false;"&gt;ContentPlaceHolder cp = new ContentPlaceHolder();
cp = Page.FindControlRecursive("Header") as ContentPlaceHolder;
if (cp != null)
{
    UserControl uc = this.LoadControl("usercontrols/static_widget.ascx") as UserControl;
    cp.Controls.Add(uc);
}
&lt;/pre&gt;Hope
this helps.&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=60c04db3-7c93-4814-a793-dd1094469b0d" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,60c04db3-7c93-4814-a793-dd1094469b0d.aspx</comments>
      <category>ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=84bf6e1f-9210-4bdf-945c-37750390156b</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,84bf6e1f-9210-4bdf-945c-37750390156b.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,84bf6e1f-9210-4bdf-945c-37750390156b.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=84bf6e1f-9210-4bdf-945c-37750390156b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Everybody is enjoying with new SQL Server 2008 intellisense feature. At the same time
you would have wondered that it is not working with new tables, views, stored procedures
created. This is due to cache refresh issue with SQL Server 2008 and you can simply
refresh the cache as explained below. 
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense1_2.jpg">
            <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense1" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense1_thumb.jpg" width="244" height="98" />
          </a>
        </p>
        <p>
I have added new table “Active Reports”, but it is not showing up in the
SQL Intellisense. 
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense2_2.jpg">
            <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense2" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense2_thumb.jpg" width="244" height="69" />
          </a>
        </p>
        <p>
Even if you type the sql query analyzer shows as error, even if you execute the query
it will not show error and you will be blaming the intellisense feature. 
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense3_4.jpg">
            <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense3" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense3_thumb_1.jpg" width="244" height="173" />
          </a>
        </p>
        <p>
Now, go to SQL Menu Edit -&gt; IntelliSense -&gt; Refresh Local Cache (Ctrl+Shift+R),
the intellisense detected the table as shown below. 
</p>
        <p>
          <a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense4_2.jpg">
            <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense4" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense4_thumb.jpg" width="244" height="112" />
          </a>
        </p>
        <p>
Hope this helps to the new comers of SQL 2008
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=84bf6e1f-9210-4bdf-945c-37750390156b" />
      </body>
      <title>SQL Server 2008 Intellisense Refresh</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,84bf6e1f-9210-4bdf-945c-37750390156b.aspx</guid>
      <link>http://blog.rajan.net.in/2009/03/29/SQLServer2008IntellisenseRefresh.aspx</link>
      <pubDate>Sun, 29 Mar 2009 06:45:14 GMT</pubDate>
      <description>&lt;p&gt;
Everybody is enjoying with new SQL Server 2008 intellisense feature. At the same time
you would have wondered that it is not working with new tables, views, stored procedures
created. This is due to cache refresh issue with SQL Server 2008 and you can simply
refresh the cache as explained below. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense1_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense1" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense1_thumb.jpg" width="244" height="98" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
I have added new table &amp;#8220;Active Reports&amp;#8221;, but it is not showing up in the
SQL Intellisense. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense2_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense2" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense2_thumb.jpg" width="244" height="69" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Even if you type the sql query analyzer shows as error, even if you execute the query
it will not show error and you will be blaming the intellisense feature. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense3_4.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense3" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense3_thumb_1.jpg" width="244" height="173" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Now, go to SQL Menu Edit -&amp;gt; IntelliSense -&amp;gt; Refresh Local Cache (Ctrl+Shift+R),
the intellisense detected the table as shown below. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense4_2.jpg"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="sql-intellisense4" src="http://blog.rajan.net.in/content/binary/WindowsLiveWriter/SQLServer2008IntellisenseRefresh_F505/sql-intellisense4_thumb.jpg" width="244" height="112" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Hope this helps to the new comers of SQL 2008
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=84bf6e1f-9210-4bdf-945c-37750390156b" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,84bf6e1f-9210-4bdf-945c-37750390156b.aspx</comments>
      <category>SQL Server 2008</category>
    </item>
  </channel>
</rss>