Web Parts custom property not showing up - sharepoint

I'm trying to create a custom property for my web part, but can't get it to show up in Sharepoint. Here's my current code :
[Serializable]
[XmlRoot(Namespace = "MyWebPart")]
[DefaultProperty("Text")]
public class MyWebPart : WebPart
{
...
[Category("My Web Parts Properties")]
[DefaultValue(defaultPropertyValue)]
[WebPartStorage(Storage.Shared)]
[FriendlyNameAttribute("Property name")]
[Description("Longer desc for my property")]
[Browsable(true)]
[XmlElement(ElementName = "SomeProperty")]
public string SomeProperty
{
get { return someProperty; }
set { someProperty = value; }
}
Is there something else required to get custom properties working?

I think you're using the wrong properties
SO - Sharepoint custom web part property does not show up in the toolbox

Related

Custom Selector not refreshing when placed in Grid

I have a custom Selector created using PXCustomSelectorAttribute class, I am not able to do AutoRefresh as this option is not available. Can anyone tell me how to Autorefresh the custom selector.
Below is an example how to create a CustomSelector and set it to AutoRefresh mode.
using PX.Objects.SO;
using PX.Objects.AR;
using PX.Data;
using System.Collections;
namespace TestLib
{
public class SOOrderExt : PXCacheExtension<SOOrder>
{
#region UsrTestField
[PXDBString]
[PXUIField(DisplayName = "TestField")]
[CustomerPriceClass()]
public virtual string UsrTestField { get; set; }
public abstract class usrTestField:IBqlField { }
#endregion
}
public class CustomerPriceClassAttribute : PXCustomSelectorAttribute
{
public CustomerPriceClassAttribute()
: base(typeof(ARPriceClass.priceClassID))
{
this.DescriptionField = typeof(ARPriceClass.description);
}
protected virtual IEnumerable GetRecords()
{
ARPriceClass epc = new ARPriceClass();
epc.PriceClassID = ARPriceClass.EmptyPriceClass;
epc.Description = PX.Objects.AR.Messages.BasePriceClassDescription;
yield return epc;
foreach (ARPriceClass pc in PXSelect<ARPriceClass>.
Select(this._Graph))
{
yield return pc;
}
}
}
}
After this you need to add the field to the UI from Layout Editor and set the AutoRefresh property in the Ext Properties section to True. See the screen-shot below.
UPDATE:
In case of Grid you need to add you will need to add Control in the Levels of the Grid like is shown on the screenshot below:
After adding the control you will see the Field Editor (3) for that field.
In the properties of the Field Editor the AutoRefresh is available and you can set it to True:

Using dropdownlist i webpart (edit mode)

I'm trying to add a checkboxlist to a webpart. In the edit mode there will be a dropdown list that will contain field names from a list and the field selected will be used as the display for the checkboxlist entries in the webpart.
I have not be able to find any examples on how to get this working.
Use a custom ToolPart to create your dropdown property as such:
public class DropdownToolPart : ToolPart
{
protected override void CreateChildControls()
{
DropDownList dropdownList = new DropDownList();
// Code to add field names from SharePoint List to dropdownlist
this.Controls.Add(dropdownList);
base.CreateChildControls();
}
public override void ApplyChanges()
{
CheckBoxListWebPart myWebPart =
(CheckBoxListWebPart)this.ParentToolPane.SelectedWebPart;
//You will need to get the selected value of the dropdown by finding it
//in the Controls collection.
string selectedValue = ...
myWebPart.CheckBoxListDisplayField = selectedValue;
}
}
Your WebPart should do the following to include the ToolPart:
public class CheckBoxListWebPart: WebPart
{
public string CheckBoxListDisplayField { get; set; }
public override ToolPart[] GetToolParts()
{
ToolPart[] toolParts = new ToolPart[1];
DropdownToolPart myToolPart = new ToolPart();
toolParts[0] = myToolPart;
return toolParts;
}
}
From there you should be able to create your checkboxlist in the CreateChildControls method of the CheckBoxListWebPart. In there you will need to load the items from your SharePoint list and then use the CheckBoxListDisplayField value to select the exact field value from each item.

Type Conversion Error for casting UI.Usercontrol to custom conrol in Class Library

I've 3 of .NET Projects.
One of these project is an ASP.Net Web Form Application named Index. And the other projects are listed below
Index.Database Project is Database Layer
Index.Platform Project is Bussiness layer.
In bussiness layer im loading UserControls. There is information bout these UserControls in db. (Path, ascx file, name, Title, Content, Positions etc )
In bussiness layer i created a class drived from UserControl named ModuleControl.
Index.Platform referenced by System.Web.dll also uses Using System.Web.UI.WebControls.
I'm planning to use this ModuleControl fields in my loaded UserControls. There is another class named IndexSite instanced on Default.aspx's Load_Page event.
namespace Index.Platform.Modules
{
public class ModuleControl : System.Web.UI.UserControl
{
public string Title { get; set; }
public bool ShowTitle { get; set; }
public string Content { get; set; }
public ModuleControl()
{
}
}
}
//Index.Platform.IndexSite
private void InitializeModules(System.Web.UI.Page page)
{
string mPath = null;
try
{
ModuleDictionaryList = DBFactory.LoadModules();
PositionList = DBFactory.PositionList;
ModuleList = DBFactory.ModuleList;
foreach (KeyValuePair<string, List<module>> pair in ModuleDictionaryList)
{
foreach (var item in pair.Value)
{
mPath = "/Modules/" + item.Name + "/" + item.Name + ".ascx";
iControl = (ModuleControl)page.LoadControl(mPath);
ShowTitle = Convert.ToBoolean(item.ShowTitle);
iControl.ShowTitle = ShowTitle;
iControl.Title = item.Title;
iControl.Content = item.Content;
panel = (PlaceHolder)page.Master.FindControl(item.Position);
panel.Controls.Add(iControl);
//HttpContext.Current.Response.Write(item.Position + "<br>");
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
this class takes an argument from Default.aspx. Page sends its self.
protected void Page_Load(object sender, EventArgs e)
{
IndexSite site = IndexSite.Instance.Create(this);
}
Yes, In Bussines layer I use LoadControl method to load USerControl also im adding these controls to a panel control which is in MasterPage (PlaceHolder).
My problem is in this line: iControl = (ModuleControl)page.LoadControl(mPath);
I cant cast UserControl to ModuleControl. Remember this ModuleControl drived from UserControl and all of my ascx file drived from ModuleControl class.
Throws this error: "Unable to cast object of type 'ASP.modules_mod_login_mod_login_ascx' to type 'Index.Platform.Modules.ModuleControl'."
If i do these proccess in Main application there is no error for casting ModuleControl.
When id seperate my application to 3. I stuck here.

How to set EditorPart header in SharePoint WebParts?

I m trying to set the header for the custom Editor Part section. Any ideas how to do it?
EditorPart Class:
public class YourCustomEditorPart:System.Web.UI.WebControls.WebParts.EditorPart{
protected override void CreateChildControls() {
this.Title = "Editor Part Title Here";
...
}
}
Tell the web part that it should use this editor part, instead of the attributed properties.
WebPart Class:
public class YourWebPart:System.Web.UI.WebControls.WebParts.WebPart, IWebEditable {
...
EditorPartCollection IWebEditable.CreateEditorParts() {
// control the editorparts
List<EditorPart> editors = new List<EditorPart>();
YourCustomEditorPart editorPart = new YourCustomEditorPart();
editorPart.ID = this.ID + "_editorPart";
editors.Add(editorPart);
return new EditorPartCollection(editors);
}
...
}
Check out the below series for details. (Include download source code)
http://www.wictorwilen.se/Post/Web-Part-Properties-part-1-introduction.aspx
http://www.wictorwilen.se/Post/Web-Part-Properties-part-2-Editor-Parts.aspx

Passing Multiple parameters from Custom WebPart to Reporting services Report Viewer webpart

I working with Reporting services in Sharepoint Mode, I am able to show the report in Sql Server Reporting services report viewer , the report has multiple parameters , My question is how do I pass more than one parameter from a custom web part to this report.
I am able to pass one parameter by implementing the ITransformableFilterValues interface in the custom webpart , what I want to do is pass more than one parameter .
Ex: If there are 2 parameters on report then i should able to map each from the control in webpart.
Here is the Code for Custom Webpart:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using aspnetwebparts = System.Web.UI.WebControls.WebParts;
//using Microsoft.Office.Server.Utilities;
using wsswebparts = Microsoft.SharePoint.WebPartPages;
//using Microsoft.SharePoint.Portal.WebControls;
using System.Collections.ObjectModel;
using Microsoft.SharePoint.Utilities;
using System.Data;
using System.Collections;
namespace CustomWebPart
{
/// <summary>
/// Used to provide filter values for the status report.
/// </summary>
public class StatusReportFiler : aspnetwebparts.WebPart, wsswebparts.ITransformableFilterValues
{
DropDownList ddlCategory;
ListItem lstItem;
Label lblCaption;
public virtual bool AllowMultipleValues
{
get
{
return false;
}
}
public virtual bool AllowAllValue
{
get
{
return true;
}
}
public virtual bool AllowEmptyValue
{
get
{
return false;
}
}
public virtual string ParameterName
{
get
{
return "Category";
}
}
public virtual ReadOnlyCollection<string> ParameterValues
{
get
{
string[] values = this.GetCurrentlySelectedCategory();
return values == null ?
null :
new ReadOnlyCollection<string>(values);
}
}
protected override void CreateChildControls()
{
lblCaption = new Label();
lblCaption.Text = " Category: ";
Controls.Add(lblCaption);
ddlCategory = new DropDownList();
ddlCategory.AutoPostBack = true;
lstItem = new ListItem();
lstItem.Text = "Select All Category";
lstItem.Value = "0";
ddlCategory.Items.Add(lstItem);
lstItem = null;
lstItem = new ListItem();
lstItem.Text = "BING";
lstItem.Value = "Bing";
ddlCategory.Items.Add(lstItem);
lstItem = null;
lstItem = new ListItem();
lstItem.Text = "Google";
lstItem.Value = "Google";
ddlCategory.Items.Add(lstItem);
lstItem = null;
Controls.Add(ddlCategory);
// base.CreateChildControls();
}
[aspnetwebparts.ConnectionProvider("Category Filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
public wsswebparts.ITransformableFilterValues SetConnectionInterface()
{
return this;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
public string[] GetCurrentlySelectedCategory()
{
string[] selCategory = new string[1];
selCategory[0] = ddlCategory.SelectedValue;
return selCategory;
}
protected override void RenderContents(HtmlTextWriter htmlWriter)
{
/*htmlWriter.Write("<table border=\"0\" width=\"100%\">");
htmlWriter.Write("<tr><td>");
lblCaption.RenderControl(htmlWriter);
htmlWriter.Write("</td></tr>");
htmlWriter.Write("<tr><td>");
lblCaption.RenderControl(htmlWriter);
htmlWriter.Write("</td></tr>");
htmlWriter.Write("</table>");*/
this.EnsureChildControls();
RenderChildren(htmlWriter);
}
}
}
Once you build this Webpart deploy it to SharePoint.
Create a Webpart page in Sharpoint , Add the Custom Web Part to the page .
Once you add it you will be able to see the dropdownlist with values on the Webpart .
In another Add Webpart Section add a Sql Server Reporting Sevices ReportViewer web part and set the report URL in the properties section and click apply , this report should have the same parameter name as in Custom Webpart.
In the Custom Webpart click on Edit -> Connections-> Send Category Filter To -> ReportViewer - AAAA(This is the ReportName I Guess). This will popup a Window with the mapping section , Map the Filer Category to Filtered parameter on the Report and click Finish . This will pass the value from the Webpart to the Report.
Hope this helps.
I'm not sure about SharePoint integrated mode, but ReportServer correctly accept parameters passed via URL string.

Resources