dkl:Is it possible to access Page from ViewUserControl that is rendered using Html.RenderPartial?
No, they are completely separate.
One way to do it is to use HttpContext.Items
public static void RegisterScript( this HtmlHelper helper, string scriptUrl ) {
var items = helper.ViewContext.HttpContext.Items;
if( items.ContainsKey("scripts") )
(items["scripts"] as List<string>).Add( scriptUrl );
else
items.Add( "scripts", new List<string>{ scriptUrl } );
}
public static string OutputScripts( this HtmlHelper helper ) {
var items = helper.ViewContext.HttpContext.Items;
if( !items.ContainsKey("scripts") )
return string.Empty;
var scripts = items["scripts"] as List<string>;
// generate and return <script> tags
}
So you can call Html.RegisterScript( "~/Content/scripts/abc.js" ) from anywhere, in any view, as long as it's part of the same request.
I would use something other than "scripts" tho, to avoid naming collisions.