SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For our web site we would like to be able to have a combo box which the end user selects a “Province/State” from the drop down menu. Depending on which “Province/State” he selects, some web parts will be shown (content) and some parts will not be shown.. Is there any way to do this easily with Sharepoint?

My idea was to have some sort of global variables and have them turned true or false, depending on which ones are true/false, shows/hides certain web parts (content). Ideally we would like to have an abstract base class so that every time that we need a conditionally visible webpart, all that we need to do is to implement the condition.. However for now we tried to make a webpart that shows content depending on some query string parameter.. this is what we have..

public  class QueryStringTrimmedControl : ConditionallyVisibleControl  
    public string Parameter { get; set; }  
    public string Value { get; set; }  

    public override bool ShouldBeVisible  
            bool shouldBeVisible = Page.Request.QueryString[ParameterName] == Value;  

            return shouldBeVisible;  

Can you inform/help me modify this to reflect web parts?

Thanks and please let me know if Sharepoint provides an easier solution.

share|improve this question
@TheWorksOak: I've pasted your code in so it's easier for answerers to see. You can also use this feature and it will syntax highlight. Thanks for your question! – Alex Angas Apr 1 '10 at 23:42

Another option is JavaScript/jQuery on the client side. Depending on the selection, you just hide or show the Web Parts with the script. This will be a much better user experience than a postback.

share|improve this answer
thanks for the suggestion. We don't really wish to use JQuery because the director isn't liking the java script idea. – Anonymous Mar 31 '10 at 14:25
I would seriously reconsider the JavaScript notion. You may not like it, but it's a core part of SharePoint (already in 2007 but even bigger in 2010). JavaScript is really the way to get your site to work dynamically and light it up without having to write C# code. Low impact and easy to maintain. Discarding it is going to just make things more difficult and cause you to have to write server side code for things that don't really need it. SPServices + jQuery + 5 lines of code will get you what you need here. – Bil Simser Apr 18 '10 at 14:15

Have you considered global audiences? You could create a global audience in your SSP based on a field in Active Directory that contains their state. Then you can set the web parts to display to those audiences. It would be a little more dynamic, because your users would not have to make a selection for the content to display.

share|improve this answer
hmmm no I was unaware of global audiences.. Actually I'm looking into filtering Provinces(Canada) instead of States. Would Sharepoint know different provinces too? i'm trying to make everything for the end user, this is not for intranet or work network, i was under the assumptions that audiences was more for intranet. – Anonymous Mar 31 '10 at 13:08
Yes, it would work. Your audiences can be created using a rule that would look at a field in AD (whatever one you select) and see if it matches to put users into that global audience. You would have to create an audience for each province. Audiences can be applied to any SharePoint site, even team sites. – Lori Mar 31 '10 at 14:37

How many possible combinations of visible web parts do you have? If it's not too many, I would consider creating web part pages for each combination of visible web parts and only add those web parts to that page.

All you then need is a web part that performs the redirection to the right web part page when the selected item in the dropdown contained in that web part changes.

If you don't want to create all those web part pages, you could consider writing your own web part base class that sets this.Visible = false if a certain condition is true (e.g. read from querystring) as you suggested yourself. You could have the state/province select dropdown redirect to the current page with the appropriate querystring parameter like


share|improve this answer

We've decided to take the path of creating a global variable to deal with the issue.. however I am not very experienced with sharepoint, where would we create the global variable to work in the session and how would we implement the code to show/hide web parts into sharepoint. meaning how would we import it/where?

thanks again for all the awesome suggestions and help.

share|improve this answer
Creating a global variable to deal with the issue? Can you explain what you mean by this? How is this going to help you? – Jaap Vossers Mar 31 '10 at 17:02
@TheWorksOak: This would be better asked as a new question or else you will have two questions on this page, making it harder to understand and review answers. Please delete this answer and ask a new question, linking back to this one. Thanks! :-) – Alex Angas Apr 1 '10 at 23:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.