GibboK
GibboK

Reputation: 73908

Asp.net an TinyMce integration logic for JavaScript

I have a ASP.NET 4 page and I am using tinyMce.

My aim is to change toolbar setting for tinyMce depending on "Role" associated to logged User.

To solve it my idea is to include different version of tinyMce JavaScript code using some logic.

My questions are: - do you know a better solution? - how to include JavaScript inside the Head of the page pro grammatically?

Thanks

Upvotes: 1

Views: 216

Answers (1)

Joel Etherton
Joel Etherton

Reputation: 37523

It sounds as if you're not using MVC with MasterPages (which has a built in method for including such a JavaScript). If you're using web forms, you can put a Literal in the head of your document and assign its text value from the code behind:

<asp:Literal ID="myTinyMCEScript" runat="server" />

...

string adminScriptText = "some javascript to format for admins";
string userScriptText = "some javascript to format for knuckledraggers";
this.myTinyMCEScript.Text = (myUserRole == "admin") ? adminScriptText : userScriptText

Not terribly elegant, but effective.

Edit:

To use a file:

string adminScript = "<script language=\"javascript\" type=\"text\\javascript\" src=\"link/to/adminscript.js\"></script>";
string userScript = "<script language=\"javascript\" type=\"text\\javascript\" src=\"link/to/userscript.js\"></script>";

Since you want to store it in a file, and javascript is run in plain text at the browser, you might as well just stick it in a js file and include that js file.

Upvotes: 2

Related Questions