Skip to content
Shannon Deminick edited this page Apr 27, 2015 · 3 revisions

Webforms specific docs

Make sure that you have seen the Quick Start guide as it explains the 3 basic concepts of registering dependencies using Webforms.

When using Webforms you will have to ensure that the CDF namespace is imported in your pages or in your web.config. Example page import:

<%@ Register Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" TagPrefix="CD" %>

The ClientDependencyLoader control

Webforms requires that you have declared a ClientDependencyLoader on your master page in order to render out your dependencies. The ClientDependencyLoader is similar to ASP.Net's ScriptManager in that only one can exist on a page or during a request. To see how to register path aliases with your ClientDependencyLoader click here.

You can register a loader via markup on your page or dynamically in code behind:

Markup
<CD:ClientDependencyLoader runat="server" id="Loader" />

Dynamic Creation
bool successfullyCreated;
var loader = ClientDependencyLoader.TryCreate(this.Page, out successfullyCreated);

Dynamic/Runtime dependency registration

You can get access to the current ClientDependencyLoader if one exists by using this code:

var loader = ClientDependencyLoader.GetInstance(currentHttpContext);

if one doesn't exist, you can create one for the current request dynamically using the above syntax

Accessing the ClientDependencyLoader at runtime in your c# code means that you can register dependencies dynamically. This could be based on certain runtime criteria of the current executing page, member, or anything you want.

There are many overloaded methods of the ClientDependencyLoader.RegisterDependency to register dependencies dynamically at runtime.