Hot answers tagged user-controls
14
As James mentioned, your main mistake is that you are using Page.Header.Controls. It is much simplier: this.Controls works like a charm.
If it will not work, you should then check your delegate control declaration XML code. It should look like this:
<Control Id="AdditionalPageHead" Sequence="1000" ...
5
I'd recommend you use the ScriptLink control instead. It allows you to inject your JavaScript code into the page header, where they script-tags belong. It also allows you to avoid multiple imports of the same file.
Also, the recommended location for script files are in the /_layouts/ folder ({SharePoint Root}/TEMPLATES/LAYOUTS)
This is how to use the ...
4
You could open the site with the SystemAccount token. It is more recommended than using SPSecurity.RunWithElevatedPrivileges.
I would do it like this:
private void LoadSubsites()
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url, SPUserToken.SystemAccount)
{
using (SPWeb web = site.OpenWeb())
{
var sites = web.Webs.Select(w => ...
4
Hm.
What I would do is do the work in CreateChildControls. Have it just add the two LiteralControls to the this.Controls collection.
Then, add your ASCX to the AdditionalPageHead delegate control via your Feature. (step 33 in that article you linked to).
There is a reason (and at this time in the morning I can't remember what it is), but the Page.Header ...
4
Check out this article from Randy Drisgill. It's exactly what you need. Add the s4-notdlg css class to each div you want to hide in dialogs.
http://blog.drisgill.com/2009/11/sp2010-branding-tip-2-custom-master.html
4
You should not edit the person.aspx in the file system (updates will likely overwrite it).
SharePoint Designer is the first option, but not a good one. It will customize the page and you will not benefit from pre-compilation, and can cause headaches when upgrading!
One approach that I've previously uses is to add a new feature that puts a control in the ...
4
Just for starters, I think you have called the ExecuteOrDelayUntilScriptLoaded function in a wrong way.(You have given an extra set of curly braces for the function inside. Try this code:
string getJS(string title, string htmlContent)
{
return (string.Format(@"
ExecuteOrDelayUntilScriptLoaded(function () {
var options = ...
4
The line <Property Name="QueryPromptString">$Resources:MyResourceFile,ResourceKey</Property> wokrs fine for me.
I think that you should check your resources file. This file should contain ResourceKey which you tries to use in this property.
If you use correct resource file and key, the search control displays text depends on the site language. ...
3
It very much depends on what part of the User Control you need to work with?
The .ascx file is usually placed in the CONTROLTEMPLATES 12 hive folder.
Path: /12/TEMPLATES/CONTROLTEMPLATES
Usually, in SP2007/VS2008, you create an .ascx page (which is actually just an .aspx page without the auto generated .cs file). So you'll have to create a class file and ...
3
You can't. The syntax for @ Register with a user control is:
<%@ Register tagprefix="tagprefix"
tagname="tagname"
src="pathname" %>
Where
src
The location (relative or absolute) of the declarative ASP.NET User Controls file to associate with the tagprefix:tagname pair.
tagname
An arbitrary alias to ...
3
I got the following code from the MDSN on line libray:
<%@ Page Language="C#" %>
<%@ Reference Control="~/Controls/Spinner.ascx" %>
<script runat="server">
private ASP.Spinner Spinner1
protected void Page_Load(object sender, EventArgs e)
{
Spinner1 = (ASP.Spinner)LoadControl("~/Controls/Spinner.ascx");
}
protected void ...
2
You could certainly create logic that modifies the visibility of a control based on context, such as the page name. But I would avoid having logic that depends on hard-coded "magic" page names - I think it will lead to confusion further down the line.
When you say "template" I assume you mean page layout, and I would suggest that if you have two categories ...
2
The typical pattern used here is to use a timer job to make the changes in the web application root. As you've no doubt noticed, such changes are outside the scope of SharePoint's solution framework.
Here's an example of this from Gary Lapointe.
2
First at all you should open new site context
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
var sites = web.Webs.Select(w => new { Title = w.Title, Url = w.Url });
if ...
2
for starters, you are calculating start and end dates differently
DateTime StartTime = Convert.ToDateTime(item["EventDate"]);
DateTime EndTime = Convert.ToDateTime(item["EndDate"] ).Date;
You should also use Convert.ToBoolean() rather than casting it as x = (bool) object. I've seen the latter fail in strange ways and if that happens to be the case ...
2
A webpart is a just a kind of asp.net control, nothing specific to SharePoint considering what you want to achieve.You can use javascript\jquery\ajax to add controls dynamically.
With javascript\jquery, you can add HTML controls.Check this : http://techbrij.com/445/add-dynamic-form-elements-textbox-button-radio-checkbox
With Ajax Updatepanel, you can add ...
2
You can use jquery Ajax pretty easily and either have the response return some more html which you can add to an element on the page or build elements based on data returned.
The update panel is a simple way to implement ajax in ASP.NET but may be (depends on req) more difficult to add controls dynamically (you may end up using JS anyway.
2
I solved this problem. There is my code
private SiteMapNodeCollection GetNodes(SPWeb web)
{
HttpContext temp = HttpContext.Current;
try
{
HttpRequest request = new HttpRequest("", web.Url, "");
request.Browser = new HttpBrowserCapabilities();
HttpContext.Current = new HttpContext(request, new HttpResponse(new ...
2
You can use the WebBrowsable properties of a property in a web part. Like the following :
[WebBrowsable(true),
WebDisplayName("Items count"),
WebDescription("Items count"),
Personalizable(PersonalizationScope.User)]
public int Count { get; set; }
EDIT :
In the case (see the comments below) where you don't want to check-in/check-out the complete page, ...
2
You probably need to develop the following:
A web part which generate html with
A div which contains ajax to get the list of wiki pages, and when a page is selected ajax to get the anchors on that page
jQueryUI to hide/show that div as a dialog
Icon/link to activate jQueryUI
A web service to respond to the above ajax calls
A page layout to allow you to ...
2
It depends on what you want to achieve.
User Controls are controls which in general are ment to be statically placed on a specific pagelayout or masterpage. Like forinstance the QuickLaunch or GlobalNavigation are static controls in the masterpage, as they are ment to be shown on every single page, regardless of where you are on the site.
Webparts on the ...
2
All good answers, I'll just add that both WebPart and UserControl are derivatives of System.Web.UI.Control, and as such are just two different tools in the same box.
Normal practice is to build the UserControl, then add a WebPart that simply loads it. This gives you both options for use.
In your case you are probably going to use UserControl since ...
2
In feature 1 have an elements.xml with:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="AdditionalPageHead"
Sequence="90"
ControlSrc="~/_CONTROLTEMPLATES/XXX/first.ascx" />
</Elements>
In feature 2 have an elements.xml with:
...
2
You would be able to find the ASCX file in 14 root.
typically ..
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
copy the JS files to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033
Update the ASCX file with reference to JS from "_layouts/1033/" folder like the ...
2
Are you sure you're using a period and not a colon?
<HRPortal.TopSection runat="server" id="topSection" />
should be
<HRPortal:TopSection runat="server" id="topSection" />
Also, I have an example of a working control template that has an underscore before "controltemplates":
<%@ Register TagPrefix="myPrefix" TagName="ToolBar" ...
1
You cannot use current context inside Elevated Privileges.
SPContext.Current object is created with security context of current logged in user. So you will get access denied error.
Use the following code -
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate() {
using (SPSite ...
1
Built-in : DateTimeControl in Microsoft.SharePoint.WebControls
MSDN : Link
Article : Link
I would prefer : jQuery UI DatePicker : http://jqueryui.com/demos/datepicker/
1
That happened with me whenever there is an issue with your templates. I forgot what was my exact reason but there has to be some issue with your templates.
Also, in order to override the templates, I realized, there is an Inherits attribute set to 'TRUE' in your definition for content type. Set that to 'FALSE' and it will pick your custom templates.
1
On CreateChildControls event all the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls ...
1
When dealing with counters of any kind I like to use different approach. Even there are lots of other possibilities I like to store counter values in separated list (counter list).
In this case counter list will store value pairs: userId, current count.
Here is code:
cont = GetNextId(SPContext.Current.Web.CurrentUser.ID);
private int GetNextId(int ...
Only top voted, non community-wiki answers of a minimum length are eligible
