I have a Facebook page and want to use the like-box social plugin on it.
https://developers.facebook.com/docs/reference/plugins/like-box/
However my code doesn't want to pull up my page:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like-box" data-href="{pagename}" data-width="292" data-show-faces="true" data-stream="true" data-header="true"></div>
Related
I am trying to create EmailTemplates. I have been able to write the controller codes and also created a .txt file in a folder but when the mail is been sent, the users receive it as a HTML code.
Controller code
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email,
Firstname = model.Firstname, Surname = model.Surname, Gender = model.Gender};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
string body = string.Empty;
var root = AppDomain.CurrentDomain.BaseDirectory; using (var reader = new System.IO.StreamReader(root + #"/EmailTemplates/ConfirmAccount.txt"))
{
string readFile = reader.ReadToEnd();
string StrContent = string.Empty;
StrContent = readFile;
//Assing the field values in the template
StrContent = StrContent.Replace("[Firstname]", user.Firstname);
StrContent = StrContent.Replace("[Surname]", user.Surname);
StrContent = StrContent.Replace("[Code]", callbackUrl);
StrContent = StrContent.Replace("[Year]", DateTime.Now.Year.ToString());
body = StrContent.ToString();
}
await UserManager.SendEmailAsync(user.Id, "Confirm Your Account", body);
return View("DisplayEmail");
}
AddErrors(result);
}
return View(model);
}
Below is the .txt file content
<!doctype html>
<html lang="tr">
<head>
<meta charset="utf-8">
</head>
<body>
<p>Dear [Firstname] [Surname],</p>
<p>Kindly Confirm your Email by clicking the link below</p>
<p>[Code]</p>
</body>
The output is in form of a HTML.
The better way to send HTML formatted Email your code will be in "ConfirmAccount.htm"
<!doctype html>
<html lang="tr">
<head>
<meta charset="utf-8">
</head>
<body>
<p>Dear [Firstname] [Surname],</p>
<p>Kindly Confirm your Email by clicking the link below</p>
<p>[Code]</p>
</body>
Read HTML file Using System.IO.File.ReadAllText. get all HTML code in string variable.
string Body = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("EmailTemplates/ConfirmAccount.htm"));
Replace a Particular string with your custom value.
Body = Body.Replace("[Firstname]", user.Firstname);
Call SendEmail(string Body) Function and do a procedure to send an email.
Replace the Session email and Configuration app settings with your ones.
public static void SendEmail(string Body)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(Session["Email"].Tostring());
message.To.Add(ConfigurationSettings.AppSettings["RequesEmail"].ToString());
message.Subject = "Request from " + SessionFactory.CurrentCompany.CompanyName + " to add a new supplier";
message.IsBodyHtml = true;
message.Body = Body;
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Host = ConfigurationSettings.AppSettings["SMTP"].ToString();
smtpClient.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["PORT"].ToString());
smtpClient.EnableSsl = true;
smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["USERNAME"].ToString(), ConfigurationSettings.AppSettings["PASSWORD"].ToString());
smtpClient.Send(message);
}
You can check out in message.IsBodyHtml = true SendEmailAsyn Method
For some reason the text below, once ran through the action below creates a straight line, instead of taking into account the new line characters (\n). Are they being stripped out with the FileContentResult or GetBytes, and if so can I fix this?
"<div id=\"exp-schedule-93943\" data-href=\"https://localhost:2222/widgets/v1/schedule?eventid=93943\" data-responsive=\"true\" data-protocol=\"https\" data-width=\"100%\" data-height=\"500px\"></div>\n<script type=\"text/javascript\">\n (function (d, s, id) {\n var js, fjs = d.getElementsByTagName(s)[0];\n if (!d.getElementById(id)) {\n js = d.createElement(s);\n js.id = id;\n js.async = true;\n js.src = \"https://localhost:2222/scripts/exposure.widgets.min.js\";\n fjs.parentNode.insertBefore(js, fjs);\n }\n })(document, \"script\", \"exp.widgets\");\n</script>"
Controller Action
public virtual ActionResult Download(string text, string fileName)
{
var contentDisposition = new ContentDisposition
{
FileName = fileName,
Inline = false,
};
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(Encoding.UTF8.GetBytes(text), "text/plain");
}
Text.txt
<div id="exp-events-19185" data-href="https://basketball.exposureevents.com/widgets/v1/events?organizationid=19185" data-css="https://cdn.exposureevents.com/content/external/bballshowcase.min.css" data-responsive="true" data-protocol="https" data-width="100%" data-height="500px"></div><script type="text/javascript"> (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.async = true; js.src = "https://basketball.exposureevents.com/scripts/exposure.widgets.min.js"; fjs.parentNode.insertBefore(js, fjs); } })(document, "script", "exp.widgets");</script>
Below is my .aspx page code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="chat.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="Scripts/json2.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-1.0.0-rc2.min.js" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var query = window.location.search;
var toRemove = '?id=';
var gorge = query.replace(toRemove, '');
// Proxy created on the fly
var hub = $.connection.chatHub;
$.connection.hub.qs = "Id=" + gorge;
// Start the connection
$.connection.hub.start(function () {
//chat.server.getAllOnlineStatus();
});
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="container" class="wrap">
<div id="chatbox" class="chatbox">
<ul id="frndcontact">
</ul>
</div>
</div>
</form>
</body>
</html>
Below is my Hub class
[HubName("chatHub2")]
public class Chat2 : Hub
{
private SqlConnection objconn;
string Connstr = #"Data Source=somevalue;Initial Catalog=somevalue;Integrated Security=True;";
public Task JoinGroup()
{
return Groups.Add(Context.ConnectionId, "foo");
}
public DataTable GetDataTable(string strQuery)
{
SqlCommand objcmd;
SqlDataAdapter objda;
DataTable ds = new DataTable();
try
{
objconn = new SqlConnection(Connstr);
objconn.Open();
objcmd = new SqlCommand(strQuery, objconn);
objda = new SqlDataAdapter(objcmd);
objda.Fill(ds);
return ds;
}
catch (SqlException ex)
{
throw ex.InnerException;
}
finally
{
objconn.Close();
objcmd = null;
objda = null;
}
}
public override Task OnConnected()
{
int id = Convert.ToInt32(Context.QueryString["id"]);
string sql = string.Format("exec getfriend '" + id + "' ");
System.Data.DataTable dtgetfriend = GetDataTable(sql);
}}
Now when I am debugging I am not able to get my breakpoint hit on OnConnected. Why am I not able to start with this piece of code?
Also I have added this code in global.asax
public void Application_Start()
{
RouteTable.Routes.MapHubs();
}
You're not subscribed to the hub. Prior to start you need to declare at least one client side function and you need to reference your hub by the correct name. So if you modify your JS to be:
$(document).ready(function () {
var query = window.location.search;
var toRemove = '?id=';
var gorge = query.replace(toRemove, '');
// Proxy created on the fly
var hub = $.connection.chatHub2;
$.connection.hub.qs = "Id=" + gorge;
hub.client.foo = function() {};
// Start the connection
$.connection.hub.start(function () {
//chat.server.getAllOnlineStatus();
});
});
You'll be in good shape.
I have used the following code to use FB Like on my website...but clicking on like posts this to FB "Jonny likes http://www.site.com" but not the actual url of the page which was liked i.e "www.site.com/reports/1".
I have placed this code in the master file...
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
and this in the respective pages....
<div class="fb-like" data-href="http://citizen.tricedeals.com" data-send="true" data-width="450" data-show-faces="false" data-font="verdana"></div>
You must implement the following Meta Tags information while doing
Like press...
og:title
og:description
og:url
og:image
Code Behind
public class MetaTag
{
public string PageURL { get; set; }
public string TagName { get; set; }
public string MetaTagContent { get; set; }
public string SiteName { get; set; }
}
var fbTitleTag = new MetaTag
{
PageURL = "/",
MetaTagName = "og:title",
SiteName = "Your Site Name",
MetaTagContent = "Your Title"
};
var fbDesc = new MetaTag
{
PageURL = "/",
MetaTagName = "og:description",
SiteName = "Site Name",
MetaTagContent = "Your Description"
};
var fbUrl = new MetaTag
{
PageURL = "/",
MetaTagName = "og:url",
SiteName = "Site Name",
MetaTagContent = "URL"
};
var fbImage = new MetaTag
{
PageURL = "/",
MetaTagName = "og:image",
SiteName = "Site Name",
MetaTagContent = "Image URL"
};
System.Collections.Generic.List<MetaTag> List = new System.Collections.Generic.List<MetaTag>();
List.Add(fbTitleTag);
List.Add(fbDesc);
List.Add(fbUrl);
List.Add(fbImage);
RenderMetaTags(List, "SiteName", strRawUrl, ltMetaTags);
Here ltMetaTags is the Literal control to place in Master page. See bottom of the asnwer.
public static void RenderMetaTags(List<MetaTag> MetaTags, string sitename, string strRawURL, Literal ltlMetaHolders)
{
// ltlMetaHolders.Text = "";
foreach (MetaTag oAgentMetaTag in MetaTags)
{
RenderMetaTagByContentName(ltlMetaHolders, oAgentMetaTag.MetaTagName, oAgentMetaTag.MetaTagContent);
}
}
public static void RenderMetaTagByContentName(Literal ltlMetaHolder, string contentName, string content, bool isProp)
{
var metaTagFromat = isProp ? "<meta property=\"{0}\" content=\"{1}\" />" : "<meta name=\"{0}\" content=\"{1}\" /> ";
ltlMetaHolder.Text += string.Format(metaTagFromat, contentName, content);
}
HTML in Master Page
Following is the Literal in Head tag of Master Page
<asp:Literal ID="ltMetaTags" Mode="Transform" runat="server"></asp:Literal>
I recently ran into some similar issue I think.
I am developing a custom control for Team WebAccess 2010: The MultiValueControl for the browser. To achieve the very same experience as the MultiValueControl of the witcontrolsuite. (http://witcustomcontrols.codeplex.com/wikipage?title=Multivalue%20control&referringTitle=Home)
Therefore I am using an asp.net server control with a listbox (which is rendered as a html ) along with the following jquery drowdownchecklist (http://code.google.com/p/dropdown-check-list/)
the servercontrol looks like the following
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CodePlex.WitCustomControls.WebAccess.MultiValueControl
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:MultiValueControl runat=server></{0}:MultiValueControl>")]
public class MultiValueControl : WebControl
{
public ListBox MyListBox { get; set; }
protected override void CreateChildControls()
{
base.CreateChildControls();
MyListBox = new ListBox();
MyListBox.SelectionMode = ListSelectionMode.Multiple;
MyListBox.Items.Add(new ListItem("abcd 1"));
MyListBox.Items.Add(new ListItem("abcd 2"));
MyListBox.Items.Add(new ListItem("abcd 3"));
MyListBox.Items.Add(new ListItem("abcd 4"));
MyListBox.Items.Add(new ListItem("abcd 5"));
this.Controls.Clear();
this.Controls.Add(MyListBox);
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string resourceName1 = "WebApplication1.embedded.jquery-1.4.2.min.js";
string resourceName2 = "WebApplication1.embedded.jquery-ui-1.8.4.custom.min.js";
string resourceName3 = "WebApplication1.embedded.ui.dropdownchecklist.js";
ClientScriptManager cs = this.Page.ClientScript;
var t = typeof(MultiValueControl);
cs.RegisterClientScriptResource(t, resourceName1);
cs.RegisterClientScriptResource(t, resourceName2);
cs.RegisterClientScriptResource(t, resourceName3);
string csslink = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "WebApplication1.embedded.ui.dropdownchecklist.standalone.css")
+ "' rel='stylesheet' type='text/css' />";
var include = new LiteralControl(csslink);
this.Page.Header.Controls.Add(include);
string csslink2 = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "WebApplication1.embedded.ui.dropdownchecklist.themeroller.css")
+ "' rel='stylesheet' type='text/css' />";
var include2 = new LiteralControl(csslink2);
this.Page.Header.Controls.Add(include);
var csType = typeof(MultiValueControl);
var csName = "MultiValueControl" + MyListBox.ClientID;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(csType, csName))
{
StringBuilder csText = new StringBuilder();
csText.Append("<script type=\"text/javascript\">");
//we need to write the code the following way
csText.Append("(function($) { $(document).ready(function() {$(\"#" + this.MyListBox.ClientID + "\").dropdownchecklist();}); })(jQuery);");
//does not work as $ sign is not associated with jQuery in Team WebAccess!
//csText.Append(" $(document).ready(function() {$(\"#" + this.MyListBox.ClientID + "\").dropdownchecklist();});");
csText.Append("</script>");
cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
}
}
}
}
As you can see, I inject the scripts (which are embedded in the controls assembly) into the output page in the pre-render step.
When I run all this on an asp.net application on my local computer (I created it to prototype my solution) it works perfectly...
However that control does not work with Team WebAccess 2010, as I get the error message 'jQuery' is undefined
However when I look at my page, I can definetly see, that the three scripts I inject are just perfectly well added just before the script that throws the error:
<script src="/tfs/web/WebResource.axd?d=yGr4pF28N1gYPBSvcQ65PxwkQdtFV1bc0SJjY2M7nTK9BloSmvQxu8btRw7YDdXsjbAwSZPJBiIDI-3FSC7yFCXHjuvhkhaTAlTv2uOnOhR_y_2fLK1ahIdVYiXjEjDT2ZEI9_ozHhoJqICZykZo_rBCIDp5h7Y8v6-zWJJDJoqIIHI47YpQDhsE4-_UcYV6b6G-Cgr8MWH9AEP7CtK7Ie6wWCU1&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=9iAfN71_Hpv7igrtbh4h9pBAMBHXqUC1cX5cjkAEr1PglPvi4Uo5KLOC6tuHzMyGkpHEeBXbVeIX_NGIiKlHPSNlOjw75DksE2F-2NMVlIXoEB4uVTvyTwvt1TM3S2AGLY13hLPmM-SW12g3ZGU28PC23Vx_aYAFWSco6hgPTcCBOPuw4nSNSI72kgVuMwBjhzjxVbbzhdGLxrSAodBH5g7PATsuAN7CHE8vmi_pk9f8mW-50&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=c_BidQPb2wjtuw09st9ilCtRhA4VEjgNgJgr0VlFIRdKYP2UK1AqWS8Mo3AEiDU_MMCZkwjMVa1tTKg9UlpFoCqxCzKUhCK7Moou4ywZ74S0FJvdrcJ1cGbqtZnxrfUBLbN8_iahrG2A9Fq55up3o6R2_SlFU4d_gb_4fBXnticOG8Bl4JCbq7F2PnG-rw0fTiNwGDMwZFv1RvNJerUGYo_0Wuw1&t=634306043180265615" type="text/javascript"></script>
<script type="text/javascript">(function($) { $(document).ready(function() {$("#ctl00_c_we_ctl47_ctl00").dropdownchecklist();}); })(jQuery);</Script>
The following is the source of the page (up to my injected scripts) that does not work. (of course I dummied the fqdn name of the server ;-))
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
New Change Request: - Team Web Access
</title>
<base target="_self" />
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/tfs/web/WebResource.axd?d=fLgM8VwLkwzQwVHlt0I3zfY4k-15sHec44H9BY54wjS_v_rJDRkLrbhLIvED-zHvir1koHstEWBv_Erm3BGVmScM6OA1&t=634210436612724343" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[var JSConfig ={"showBrowserToolbar":true};//]]></script>
<script src="/tfs/web/Resources/Scripts/WindowHelpers.js" type="text/javascript"></script>
<script src="/tfs/web/Resources/Scripts/DocumentService.js" type="text/javascript"></script>
<script src="/tfs/web/ScriptResource.axd?d=DUMMYVALUE"></script>
<script type="text/javascript">
//<![CDATA[
$jslimg("imga8521f38",["/tfs/web/App_Themes/Default/Images/h-progress.gif","/tfs/web/App_Themes/Default/Images/spinner.gif","/tfs/web/App_Themes/Default/Images/tmih.gif"]);//]]>
</script>
<script src="/tfs/web/Resources/Scripts/WindowToolbar.js" type="text/javascript"></script>
<script src="/tfs/web/Resources/Scripts/SearchHelper.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
$new(windowToolbar,"ctl00_wtb",["ctl00$wtb",{"pguid":"e591d5c5-c3bd-4431-81cc-62b4fc5a6b81"}]);
//]]>
</script>
<script src="/tfs/web/Resources/Scripts/EditWorkItem.js" type="text/javascript"></script>
....
<script type="text/javascript">
//<![CDATA[
$jsreg("cd326c372",{"changeCallbackEventName":"FieldChanged","numberFormat":"None"});
$jsreg("c384acf1b",{"dropCount":8,"minDropPanelWidth":0,"maxDropPanelWidth":0,"notAllowedBGColor":"#FFFFCC","allowedBGColor":"","textBoxClass":"tswa-text-box","textBoxDisabledClass":"tswa-text-box-disabled","dropPanelClass":"tswa-font tswa-dropdowncanvas","listItemClass":"tswa-listitem","listItemHoverClass":"tswa-listitemhover","listItemSelectedClass":"tswa-listitemselected","listItemDisabledClass":"tswa-listitemdisabled","decimalChar":","});
$jsreg("c569d08c7",[]);
$new(editableDropDown,"ctl00_c_we_ctl04_wc_val",[5,cd326c372,null,c384acf1b,null,c569d08c7,c569d08c7,c569d08c7,null,"",null,""]);
//]]>
</script>
<script src="/tfs/web/WebResource.axd?d=yGr4pF28N1gYPBSvcQ65PxwkQdtFV1bc0SJjY2M7nTK9BloSmvQxu8btRw7YDdXsjbAwSZPJBiIDI-3FSC7yFCXHjuvhkhaTAlTv2uOnOhR_y_2fLK1ahIdVYiXjEjDT2ZEI9_ozHhoJqICZykZo_rBCIDp5h7Y8v6-zWJJDJoqIIHI47YpQDhsE4-_UcYV6b6G-Cgr8MWH9AEP7CtK7Ie6wWCU1&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=9iAfN71_Hpv7igrtbh4h9pBAMBHXqUC1cX5cjkAEr1PglPvi4Uo5KLOC6tuHzMyGkpHEeBXbVeIX_NGIiKlHPSNlOjw75DksE2F-2NMVlIXoEB4uVTvyTwvt1TM3S2AGLY13hLPmM-SW12g3ZGU28PC23Vx_aYAFWSco6hgPTcCBOPuw4nSNSI72kgVuMwBjhzjxVbbzhdGLxrSAodBH5g7PATsuAN7CHE8vmi_pk9f8mW-50&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=c_BidQPb2wjtuw09st9ilCtRhA4VEjgNgJgr0VlFIRdKYP2UK1AqWS8Mo3AEiDU_MMCZkwjMVa1tTKg9UlpFoCqxCzKUhCK7Moou4ywZ74S0FJvdrcJ1cGbqtZnxrfUBLbN8_iahrG2A9Fq55up3o6R2_SlFU4d_gb_4fBXnticOG8Bl4JCbq7F2PnG-rw0fTiNwGDMwZFv1RvNJerUGYo_0Wuw1&t=634306043180265615" type="text/javascript"></script><script type="text/javascript">(function($) { $(document).ready(function() {$("#ctl00_c_we_ctl49_ctl00").dropdownchecklist();}); })(jQuery);</script>
<script type="text/javascript">(function($) { $(document).ready(function() {$("#ctl00_c_we_ctl52_ctl00").dropdownchecklist();}); })(jQuery);</script>
I just have no more clues what I can do! Please HELP!!
Try putting the script registrations in the page init(). This worked for me.
Ok... as noone seemed to be able to help me, I finally could solve the problem on my own. However I am not sure if this is a sober approach. Well at least it works, right? :)
What I did was changing the "prerender" logic to not register the jQuery libs as web resource but writing them out like my own client side script.
Its rather hard to explain - so just look at the code.
base.OnPreRender(e);
// jquery control only works together with listbox
if (!(this.CheckboxList is ListBox))
return;
string resourceName1 = "CodePlex.WitCustomControls.WebAccess.embedded.jquery-1.4.2.min.js";
string resourceName2 = "CodePlex.WitCustomControls.WebAccess.embedded.jquery-ui-1.8.4.custom.min.js";
string resourceName3 = "CodePlex.WitCustomControls.WebAccess.embedded.ui.dropdownchecklist.js";
ClientScriptManager cs = this.Page.ClientScript;
var t = typeof(MultiValueControl);
WriteEmbeddedScript(cs, resourceName1, t);
WriteEmbeddedScript(cs, resourceName2, t);
WriteEmbeddedScript(cs, resourceName3, t);
//cs.RegisterClientScriptResource(t, resourceName1);
//cs.RegisterClientScriptResource(t, resourceName2);
//cs.RegisterClientScriptResource(t, resourceName3);
string csslink = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "CodePlex.WitCustomControls.WebAccess.embedded.ui.dropdownchecklist.standalone.css")
+ "' rel='stylesheet' type='text/css' />";
var include = new LiteralControl(csslink);
this.Page.Header.Controls.Add(include);
string csslink2 = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "CodePlex.WitCustomControls.WebAccess.embedded.ui.dropdownchecklist.themeroller.css")
+ "' rel='stylesheet' type='text/css' />";
var include2 = new LiteralControl(csslink2);
this.Page.Header.Controls.Add(include);
var csType = typeof(MultiValueControl);
var csName = "MultiValueControl" + CheckboxList.ClientID; // we need to add a script for each separate MultiValueControl on a page
var script = "(function($) { $(document).ready(function() {$(\"#" + this.CheckboxList.ClientID + "\").dropdownchecklist();}); })(jQuery);";
WriteScript(cs, script, csType, csName);
}
private static void WriteEmbeddedScript(ClientScriptManager cs, string resourceName1, Type t)
{
using (var reader = new StreamReader(Assembly.GetAssembly(t).GetManifestResourceStream(resourceName1)))
{
var script = reader.ReadToEnd();
WriteScript(cs, script, t, resourceName1);
}
}
private static void WriteScript(ClientScriptManager cs, string script, Type csType, string csName)
{
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(csType, csName))
{
StringBuilder csText = new StringBuilder();
csText.Append("<script type=\"text/javascript\">");
//we need to write the code the following way
csText.Append(script);
//does not work as $ sign is not associated with jQuery in Team WebAccess!
//csText.Append("$(document).ready(function() {$(\"#" + this.CheckboxList.ClientID + "\").dropdownchecklist();});");
csText.Append("</script>");
cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
}
}