About Me

Having 12 years experience in Microsoft technologies.Since more than 7 years working in SharePoint technologies. Expert in providing consultation for SharePoint projects. Hands on with development and administration.
Showing posts with label web parts. Show all posts
Showing posts with label web parts. Show all posts

Thursday, 12 December 2013

Using External Javascript, CSS or Image File in a SharePoint WebParts

Button btn;
Image img;
string imgPath;
// Referring External Javascript
ClientScriptManager cs = Page.ClientScript;
// Include the required javascript file.
if (!cs.IsClientScriptIncludeRegistered("jsfile"))
cs.RegisterClientScriptInclude(this.GetType(), "jsfile", "/_wpresources/javascript/jsscript.js");
 
btn= new Button();
btn.Text = "Click here";
// specify function name here
btn.OnClientClick = "ButtonClick()";
this.Controls.Add(btn);
// Refering External CSS
Microsoft.SharePoint.WebControls.CssLink cssLink = new Microsoft.SharePoint.WebControls.CssLink();
cssLink.DefaultUrl = "/_wpresources/styles/styles.css";
this.Page.Header.Controls.Add(cssLink);
// Using External Image
imgPath = "/_wpresources/images/Imglogo.jpg";
img.ImageUrl = imgPath;
img.ID = "image1";
 
this.Controls.Add(img);