About Me ·
At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.
A rather long title for this post, but that's what it comes down to.
I've been struggling with some problems an couldn't find anything about this issue on the web, so I decided to post my findings.
Because it is possible to place a Web Part multiple times on a SharePoint web page, SharePoint Server will assign a unique identifier to each control (that is, a Web Part and some of its child controls¹) to be able to distinguish between Postbacks originating from different Web Parts. The unique ID can be found in the ID attribute of a HTML element and looks similar to this:
TopZone defines the location of the Web Part, along with its GUID. The bold part (_ctl1) denotes the ID of the control in question, a SELECT in my case.
However, this will not work: The location and the GUID of the Web Part is evaluated when the page is rendered. These values then serve as a prefix to the control ID (_ctl1) you set in your own code. You have to retrieve the location/GUID prefix along with the control ID and combine them to the actual HTML ID. Because Web Parts should derive from Microsoft.SharePoint.WebPartPages.WebPart this is pretty easy to achieve.
// Combine the Web Part's ID and the control ID.master.Attributes.Add("onchange",
Download the source code of the sample solution.
¹ Those with an ID or a NAME.
Now playing: Audiomatix - What a day
a@href@title, blockquote@cite, em, strike, strong, sub, sup, u
Page rendered at Sunday, September 25, 2016 2:12:59 PM (W. Europe Daylight Time, UTC+02:00)
newtelligence dasBlog 2.3.257.0
© Copyright 2016, admin
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in any way.