I'm attempting to completely hide a custom web part I'm writing under specific circumstances. What I'm not finding a lot of help on is actually hiding the complete web part. Using:
this.Hide = true;
will hide the content of the web part, but it appears to leave the Chrome behind. I can't change the Chrome display, so that's not an option right now. Is there a more complete way to hide the complete web part using C#?
I'm not worried about the web part being rendered or not, just having it not visually display. What I ended up doing is changing the chrome through code if my specific situation arises.
this.ChromeType = PartChromeType.None;
this.Hidden = true;
The only way to ensure nothing is rendered to the page is to close the web part. From MSDN:
A WebPart control that is hidden
remains in its zone, is actually
rendered on its page, and participates
in page life cycle phases such as the
PreRender phase, even though it is not
visible in a browser. This is
different from WebPart controls that
are closed, because closed controls
are not even rendered on a page...
Use the SPLimitedWebPartManager and its CloseWebPart method to do this. (Be careful about disposing of SPLimitedWebPartManager as well as its Web property correctly.)
Alternatively, use a CSS or jQuery approach. The web part will still be rendered but you will be able to hide it as you originally wanted.
Related
I'm working on an XPages Mobile app using mobile controls from Extension Library.
My hope page is a menu leading to 4 different mobilePages.
I get this this is 1 XPage and we're dealing with "Virtual Pages". But is there a way to clear viewScope variables and document bindings as you go back and forth between virtual pages?
For instance. In one of my pages I ask the user for some data. 3 Fields stored in viewScope Variables. Using that I then have a button to Create a new document which gets bound to a panel and then I do things with it.
If the user hits "back" from the menu bar, to go to the Home screen and then goes back to the same page I want to clear everything and start all over.
setting resetContent= true doesn't do anything here.
My virtual page is a custom control and I tried to clear everything on beforePageLoad but that wiped it all during a manual refresh.
I tried hooking into the rendered property of the back button but that fired during a full page refresh. Possibly I could live with partial refreshes but someone might still manually refresh it.
Any way to get this ability inside the single page app mobile context?
Thanks!
See the following XSnippet on OpenNTF.org for your answer and a worked example - have fun! BTW: this is something we want to support on the Mobile App Page in an upcoming release - for now you can use the worked example I provide on XSnippets!
http://openntf.org/XSnippets.nsf/snippet.xsp?id=calling-server-side-jscode-during-mobile-page-transitions
Have you tried using requestScope for the virtual page bindings? From your description, it sounds like this would be the correct scope to use.
i create a website on my local machine but i can't add webpart to web page, it don't rise any error but th webpart don't display to the page. anyone help me.
Thanks
I know this is an old question, but it's ranking high in Google results, so I figured I'd answer it anyway.
Make sure you're not running any code in the layout page's codebehind that calls and then closes SPContext.Current.Web. I had this exact behavior and that was the culprit
To test, add a different web part to a default page layout. If it adds, then it's either your web part or your code behind. If you can't add any web parts to your custom layout, it's your code behind. If it's just your web part, it's your web part.
Remember, SPContext.Current.Web returns a reference to the current SPWeb object. SharePoint will close the object itself when it's done, and closing it early can cause "unpredictable behavior."
We had the same problem with Firefox some time ago, but the problem disappeared when we installed SP2 for SharePoint 2007. The only thing that surprises me is that you also have the problem with IE.
I am stuck with a problem. I am having tool part where I get all the Lists present in the Site.
I have other web part which should get the selected List in the tool part.
I see that the web part is loaded first then the tool part. so the web part is unable to the List selected in the tool part.
Please note that the text box is in a User Control.
Please help me.
I have looked at your code and found the following:
First things first. You need to move AWAY from using ToolParts and the SharePoint native webpart. they are deprecated and are a remnant from SPS2003. In MOSS / WSS 3.0 you can and should use the ASP.NET WebPart.
Secondly, I think you are mixing things up. The ToolPartGetLists is not a toolpart, it is a webpart, that in itself loads the CustomToolPart, which in turn allows you to select a list.
This toolpart is only shown when you edit the shared webpart in the UI. The list you select is then persisted to the SelectedList property of the webpart using the toolpart.
The connected webpart then tries to read the SelectedList property I guess.
Like I said, I could go and try to fix the code for you, but it is not the way to go, you really (REALLY) need to switch to ASP.NET WebPart based webparts. The native sharepoint one WILL be fased out in the (near) future.
Here you can find an example, with code! (scroll to bottom for download link). As a bonus, it uses the built in sharepoint listpicker
I don't know of any way you could control the load order of elements (web parts) on the same page.
Sounds more like you want to have your second web part (the display of the lists) have a "default" when the page loads--which could be empty. Then it would be changed to the selected list only when the user clicked a new selection in the other web part (the list of lists).
The biggest problem I have faced so far in sharepoint, is to be able to make a certain webparts invisible or hide if the user is not logged in, basically to be able to make an audience for anonymous user.
If anyone knows how to do that, please help.
As far as I know the only way to do that out of the box is to wrap the complete Web Part Zone in a SPSecurityTrimmedControl.
Another thing you could try is to create Control Adapter for every single Web Part type and then implement the display logic in there. Please notice though, that this approach has some limitations. The most important is that all Control Adapters will be applied to every single Web Part in the given Web Application of the given type.
A little trick I use is to hide the web part in your CSS (either your master CSS or another web part), and then use ANOTHER web part - this time targeted to authenticated users - that overrides the initial CSS, making the content visible. I wouldn't recommend it for secure content, since the web part is still being rendered at the client, but if you're going for UI elements, this works perfectly.
Can this be done by setting a property?
I'd prefer that approach then to remove all security before re-adding it.
(As this may have other consequences.)
Another option I can think of is to replace the particular webpart dll with a temporary one, and restart the .net process, but that's not an approach I like at all.
What other options are there? AM I missing something obvious?
What i'm trying to do is find a way to disable a webpart while we update the underlying database schema it's using, for example.
So we'd ideally like to disable a specific webpart for all users, whether it's on a mysite, or a community site, make the required changes and then re-enable it.
Thus decreasing the downtime for users.
Whatever the solution is, we need to be able to do it across multiple front end servers, on potentially two farms easily.
Thanks for your help.
Go to Site Actions -> Edit Page
You get all the web parts edited. Click on the "Edit" dropdown of the Web Part you want to disable and choose "Close".
The web part disappears, but don't fear! It's not gone for good!
To have it back:
-> click to Add a new Web Part -> Advanced Web Part Gallery and Options.
The very first option you have is to choose among "Closed Web Parts". When clicking on that link, you will have displayed a list of all the web parts you had closed. Just add the one you want back!
In the web.config, you can set safe="false" for the SafeControl tag for the webpart. This will cause the web part to render an error message until you set it back to true.
http://technet.microsoft.com/en-us/library/cc287909.aspx
write code to set a value in property bag of the site, set the value through the code and in page lode of the web part check for the value of the property bag if set show the content else just skip.
hope you understood if not let me know i will make it clear.