I am developing a custom list-search tool. I have multiple custom properties to retain which list the search queries, as well as which fields to query in the search.
EXAMPLE UI
DROPDOWN(Selected fields in list) TEXTBOX(Query) SEARCHBUTTON
My issue is that when loading the WebPart, the “Fields to Search” property is being set before the “List to Search” property, which causes and error as I have a check to make sure the Fields actually exist in the correct list before adding them to the dropdown.
Is there any way to designated which order the web part properties get set in on load?
I think in this case, it would be easiest for you to move your validation logic out of your property setters and into another method (
CreateChildControlsfor instance). By doing so, you will remove any dependencies on property-setting order.I typically have no logic (or very, very little) in my Web Part properties. I do all my validation in/from
CreateChildControlsright at the very beginning. Then if some property has a missing or invalid value, I can throw an exception or, more typically, write out a descriptive message using the Web Part’s output.