Showing posts with label Webparts. Show all posts
Showing posts with label Webparts. Show all posts

Monday, 4 February 2013

Close and re-open web parts

If you wanna hide a web part for a while so that you can re add it to the page later without having to reconfigure all of it settings this is what you do:

Close the web part from the web part drop down menu (the arrow that appears in the top left cornor of the web part when you hover over it):




When you later wanna re enable it, you click add web part as normal,k however this time you click the "Closed webparts group" and add it from here:


Monday, 10 December 2012

Read web part properties with javascript

The scenario: You have a visual web part with one or more properties you need to read from some javascript code related to the web part.

One way to do this, is to add a hidden html input control (with runat=server set) to the user control.
In the code behind for the user control assign the value of the property to the input element like this:



        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (this.WebPart != null)
            {
                wsurl.Value = WebPart.ValidationWebServiceUrl;
            }
        }

In the code above "wsurl" is the id of my hidden html input control, and "ValidationWebServiceUrl" is the property on my web part.

Voila - now you can read the value of the input element containing the property value from javascript. :-)