SharePoint Events

 ProjectReady Applications for the AEC
 01/27/16 - Webcast: Satisfy Regulatory & Compliance Demands in SharePoint and Office 365
 01/28/16 - Webcast: What's NEW with Microsoft Power Business Intelligence
 02/02/16 - Webcast: CAD and Revit Management in the Cloud with ProjectReady CAD
 02/03/16 - Webcast: The Value of the Microsoft Cloud: Leveraging the Scalability, Affordable Storage & Security Features of Office 365
 03/01/16 - Webcast: Redline, Markup and Redact Legal Content with Any Device in SharePoint & Office 365
 03/02/16 - Webcast: Unify Your Systems and End Content Chaos in the AEC
 03/03/16 - Webcast: Resource and Task Management Made Easy for the AEC
 03/04/16 - Webcast: Enterprise Records Management in SharePoint & Office 365
(More Links...)

 SharePoint Videos

 What’s Coming in Office 365 & SharePoint 2016
 Automating Contract Management with Workflow in the Cloud or On-Premise
 Manage Email in the Cloud or On-Premise with SharePoint & Office 365
 Governance Essentials for SharePoint 2013 and SharePoint Online
 Easily Move Email, Files and SharePoint to Office 365
 Enterprise Workflow in the cloud with SharePoint & Office 365
 Why SharePoint 2013
 SharePoint 2013 vs SharePoint Online and Office 365 Security, Compliance and eDiscovery
 Expanding the Use, Potential and Value of SharePoint and Office 365 through 3rd Party Applications
 Keys to Successful SharePoint Initiatives and User Adoption
 SharePoint 2013 vs. SharePoint Online: Workflow
 Ensure Auditability and Compliance with Advanced Workflows in SharePoint
 SharePoint 2013 vs. SharePoint Online and Office 365: Enterprise Content Management
 SharePoint 2013 vs. SharePoint Online and Office 365: Business Intelligence
 SharePoint 2013 vs. SharePoint Online: Search
 Power Business Intelligence for SharePoint Online and Office 365
 Enforce Governance with Ease in SharePoint and SharePoint Online
 Digitize Paper Driven Processes with Dynamic Web Forms in SharePoint
 Boost Performance and Eliminate Storage Limitations in SharePoint
 Out of the Box Business Intelligence and Reporting in SharePoint 2013
(More Links...)

 Archives ‭[1]‬

Opening SharePoint Links in a new window
Mail Enabled Lists vs. The Missing Windows 2008 POP3/IMAP Server 
7 Tools for SharePoint Developers
Public Facing Masterpage Techniques
How to Quickly Deploy and Activate a Timer Service to Your Site Collection
Custom SharePoint Master Page Feature with WSP Builder
Date Math with InfoPath
Enterprise Search Tricks and Tips Part 1
Populating Word Documents With SharePoint Data. Try The DIP!
Programmatic Deep Dive into Blank SharePoint Lookup Columns
1 - 10Next
Creating and Accessing Visual Webpart Properties from JavaScript

By: Omar Stewart

 

Everyone is familiar with the SharePoint Visual WebPart Project Template available in Visual Studio 2010, it makes it ultra-easy to create a Visual WebPart. There are times when you want to create custom properties for your visual WebPartwhich is ultra easy to do. What becomes tricky is how to access these properties from your user control, furthermore, how would you get these properties into JavaScript. Today I'll walk you through a simple demonstration of how to get this done. This will be a simple webpart to demonstrate the functionality, no bells and whistles here.

 

First we'll create a simple Visual WebPart from Visual Studio:

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript 

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

We'll Open our VisualWebPart1.ascx User Control to add a plain HTML Button, and a simple asp:Literal which will hold the value of our property.

 

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

 

Then we'll navigate to our VisualWebPart1.cs to create our custom property. Our property will be a simple string.

 

The_SharePoint_Blog_Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

 

Now back in our user control, we'll jump to the code behind file (VisualWebPart1UserControl.ascx.cs), here we will need to access the user control's parent which is really the WebPart, then we can have access to our custom properties.

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

Now that we can access our parent WebPart and its properties, lets create a hidden input field and assign our property as its value.

 

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

Our job is pretty much done,  lets write a JavaScript function and access our custom property.

Back in VisualWebPart1UserControl.ascx add the following script:
 

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

Then update the input button's onclick function to call our function.

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

That's it, deploy the project and add the WebPart to a page.

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

Now if we edit  our WebPart, we should see our custom Web Part Properties Section.

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

If we enter  some text in our custom property and click OK, our webpart should alert the property:

 

The_SharePoint_Blog_Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

Voila! Clean markup, with our properties in a simple input field.

 

Creating_and_Accessing_Visual_Webpart_Properties_from_JavaScript

 

I hope this was helpful, and I'm always looking to learn about alternative ways to get this done. 

 

By: Omar Stewart

        

 Subscribe

  GigWerks RSS  Gig Werks Mailing List 

 Contact Us

 Connect

 Resources

 On Demand SharePoint Webcast Recordings
 Upcoming Webinars
 SharePoint Resources
 Business Intelligence Resources
 Gig Werks Website



©2009 Gig Werks. All rights reserved. Privacy Policy