Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...First release: javascript skin object (JQUERYUI or LIGHTBOX support)First release: javascript skin object (JQUERYUI or LIGHTBOX support)
Previous
 
Next
New Post
12/17/2009 4:37 PM
 

I'm not ready to package it up into an extension yet, but here it is. It's usable from ASCX skin files only. I was frustrated with the inability to add script to page headers from my skin. So this script plugs into the ASP.NET ScriptManager to add script includes, or script blocks to the page header. TESTED IN DNN 5.2.0 ONLY! And I shouldn't have to mention that you should use it at your own risk.

Syntax:

All Posible Options: 
<uc1:script runat="server" 
	id="something" 
	Src="string" 
	RequireJquery="false" 
	UseScriptManager="true" 
	AddScriptTags="false" 
	IsStartupScript="false"
>
	//javascript literal
</uc1:script>

where:

id		The key of the script tag. Useful to prevent naming 
		collisions between controls, modules, and script. 
		e.g. Your skin file and containers can all include 
		jQueryUI, but the ScriptManager automatically includes 
		the necessary js file ONCE per unique id value.
RequireJquery	Triggers DNN jQuery to be loaded. (default=false)
UseScriptManager
		true = Uses System.Web.UI.ScriptManager to manage the script inclusion.
		false = includes the script files manually. (NOT IMPLEMENTED)
		(default=true)
AddScriptTags	Use with the script literal (tag inner contents). (default=false)
IsStartupScript	Delay script execution until the page is fully loaded. (default=false)

Usage:

<%@ Register TagPrefix="uc1" TagName="SCRIPT" Src="~/path/to/script.ascx" %>
<uc1:script id="test1" src="js/test.js" runat="server"></uc1:script>
<uc1:script id="test2" runat="server" IsStartupScript="true" AddScriptTags="true">
  this is test2 script!");
</uc1:script>
<uc1:script id="test3" src="js/lightbox.js" runat="server" RequireJquery="true"></uc1:script>

Source: script.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="script.ascx.cs" Inherits="skin_script" %>

Source: script.ascx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

[DefaultProperty("Src"),
 ParseChildren(true, "ScriptLiteral" ),
 ToolboxData("<{0}:Script runat=server>")]
public partial class skin_script : DotNetNuke.UI.Skins.SkinObjectBase {
	public db4o_script()
		: base() {
		this.Src = null;
		this.ScriptLiteral = null;
		this.RequireJquery = false;
		this.UseScriptManager = true;
		this.AddScriptTags = false;
		this.IsStartupScript = false;
	}

	#region Properties
	[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
	 DefaultValue(null)]
	public string Src { get; set; }

	[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
	 DefaultValue(null),
	 PersistenceMode(PersistenceMode.InnerDefaultProperty)]
	public string ScriptLiteral { get; set; }

	[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
	 DefaultValue(false)]
	public bool RequireJquery { get; set; }

	[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
	 DefaultValue(true)]
	public bool UseScriptManager { get; set; }

	[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
	 DefaultValue(false)]
	public bool AddScriptTags { get; set; }

	[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
	 DefaultValue(false)]
	public bool IsStartupScript { get; set; }
	#endregion

	protected void Page_Load(object sender, EventArgs e) {
		if (!String.IsNullOrEmpty(this.Src) && !String.IsNullOrEmpty(this.ScriptLiteral))
			throw new ArgumentException("Cannot specify both a src attribute and a script body.");

		if (!this.UseScriptManager)
			throw new NotImplementedException();

		string id = this.ID.ToLowerInvariant();

		if (this.RequireJquery) {
			if (!DotNetNuke.Framework.jQuery.IsInstalled)
				throw new NotSupportedException("jQuery is required, but not installed.");
			DotNetNuke.Framework.jQuery.RequestRegistration();
		}

		if (!String.IsNullOrEmpty(this.Src))
			AddScriptSrcToPage(id, this.Parent.ResolveUrl(this.Src));

		if (!String.IsNullOrEmpty(this.ScriptLiteral))
			AddScriptToPage(id, this.ScriptLiteral);
	}

	protected void AddScriptToPage(string key, string scriptBody) {
		if (UseScriptManager) {
			if (DotNetNuke.Framework.AJAX.IsInstalled())
				DotNetNuke.Framework.AJAX.RegisterScriptManager();

			if (!IsStartupScript)
				ScriptManager.RegisterClientScriptBlock(this, this.GetType(), key, scriptBody, this.AddScriptTags);
			else
				ScriptManager.RegisterStartupScript(this, this.GetType(), key, scriptBody, this.AddScriptTags);
		}
		else {
			
		}
	}

	protected void AddScriptSrcToPage(string key, string url) {
		if (UseScriptManager) {
			if (DotNetNuke.Framework.AJAX.IsInstalled())
				DotNetNuke.Framework.AJAX.RegisterScriptManager();

			ScriptManager.RegisterClientScriptInclude(this, this.GetType(), key, url);
		}
		else {
		}
	}
}

 

 
New Post
1/2/2010 11:15 PM
 

I polished it up and packaged it as a SkinObject. You can use either the token [Db4oSCRIPT], or register the control ~/DesktopModules/db4o/script.ascx and use as above.

Contact me for the code. I'll try to post it somewhere soon.

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...First release: javascript skin object (JQUERYUI or LIGHTBOX support)First release: javascript skin object (JQUERYUI or LIGHTBOX support)


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out