1

I have created a XsltListViewWebPart using the designer and copied the same page to a site page. This has been deployed from the visual studio. Now, I have added a code behind file. But, I'm not able to get the XsltListViewWebPart inside the code behind. I need to set some properties using the code behind. Getting null for the below mentioned code. How can I get that ?

var cntl = this.FindControl("g_e4c4ddc3_e234_43d2_9a4b_a1c391d69f17") as XsltListViewWebPart;

1 Answer 1

3

To get a WebPart you use the Limited Web Part Manager

The SPWebPartManager manages all the Web Part controls, functionality, and events that occur on a webpage..

For example

using (SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(this.Page.Request.Url.AbsolutePath, PersonalizationScope.Shared))
{
    foreach (System.Web.UI.WebControls.WebParts.WebPart current in wpm.WebParts)
    {
        if (current is XsltListViewWebPart)
        {
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.