I have a question about how things should behave for a Read Only user in the folowing scenario.
I have an example up and running with three web parts
1. Contract Dropdown list (provider) - user selects a contract
2. Period Dropdown list (consumer) - Based on selection of contract this is populated with a list of items
3. Display web part - based off selection of period a string is displayed.
Here is the code of the three.
Contract
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace ConnectingWebParts.StringProvider
{
[ToolboxItemAttribute(false)]
public class StringProvider : WebPart, IContractID
{
private String _contractID = "";
private Button myButton;
private DropDownList myDropDownList;
[Personalizable]
public string ContractID
{
get
{
return _contractID;
}
set
{
_contractID = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
myDropDownList = new DropDownList();
myDropDownList.Items.Add(new ListItem("Contract A", "A"));
myDropDownList.Items.Add(new ListItem("Contract B", "B"));
myDropDownList.Items.Add(new ListItem("Contract C", "C"));
myDropDownList.Items.Add(new ListItem("Contract D", "D"));
myDropDownList.Items.Add(new ListItem("Contract E", "E"));
Controls.Add(myDropDownList);
myButton = new Button();
myButton.Text = "Populate Periods";
Controls.Add(myButton);
myButton.Click += new EventHandler(myButton_Click);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
void myButton_Click(object sender, EventArgs e)
{
ContractID = myDropDownList.SelectedValue.ToString();
}
[ConnectionProvider("Provider for String From Contract DropDown", "ContractIDProvider")]
public IContractID ContractIDProvider()
{
return this;
}
}
}
Period
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data.SqlClient;
namespace ConnectingWebParts.StringConsumer
{
[ToolboxItemAttribute(false)]
public class StringConsumer : WebPart, IPeriodID
{
private IContractID _myProvider;
private String _periodID = String.Empty;
private DropDownList myDropDownList;
private Button myButton;
[Personalizable]
public string PeriodID
{
get
{
return _periodID;
}
set
{
_periodID = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
myDropDownList = new DropDownList();
myDropDownList.Items.Add("--SELECT CONTRACT--");
Controls.Add(myDropDownList);
myButton = new Button();
myButton.Text = "Display Period ID";
Controls.Add(myButton);
myButton.Click += new EventHandler(myButton_Click);
}
protected override void OnPreRender(EventArgs e)
{
EnsureChildControls();
if (_myProvider != null)
{
if ((_myProvider.ContractID != "") && (_myProvider.ContractID != null))
{
myDropDownList.Items.Clear();
switch (_myProvider.ContractID)
{
case "A":
myDropDownList.Items.Add(new ListItem("Period A1", "A1"));
myDropDownList.Items.Add(new ListItem("Period A2", "A2"));
myDropDownList.Items.Add(new ListItem("Period A3", "A3"));
myDropDownList.Items.Add(new ListItem("Period A4", "A4"));
myDropDownList.Items.Add(new ListItem("Period A5", "A5"));
break;
case "B":
myDropDownList.Items.Add(new ListItem("Period B1", "B1"));
myDropDownList.Items.Add(new ListItem("Period B2", "B2"));
myDropDownList.Items.Add(new ListItem("Period B3", "B3"));
myDropDownList.Items.Add(new ListItem("Period B4", "B4"));
myDropDownList.Items.Add(new ListItem("Period B5", "B5"));
break;
case "C":
myDropDownList.Items.Add(new ListItem("Period C1", "C1"));
myDropDownList.Items.Add(new ListItem("Period C2", "C2"));
myDropDownList.Items.Add(new ListItem("Period C3", "C3"));
myDropDownList.Items.Add(new ListItem("Period C4", "C4"));
myDropDownList.Items.Add(new ListItem("Period C5", "C5"));
break;
case "D":
myDropDownList.Items.Add(new ListItem("Period D1", "D1"));
myDropDownList.Items.Add(new ListItem("Period D2", "D2"));
myDropDownList.Items.Add(new ListItem("Period D3", "D3"));
myDropDownList.Items.Add(new ListItem("Period D4", "D4"));
myDropDownList.Items.Add(new ListItem("Period D5", "D5"));
break;
case "E":
myDropDownList.Items.Add(new ListItem("Period E1", "E1"));
myDropDownList.Items.Add(new ListItem("Period E2", "E2"));
myDropDownList.Items.Add(new ListItem("Period E3", "E3"));
myDropDownList.Items.Add(new ListItem("Period E4", "E4"));
myDropDownList.Items.Add(new ListItem("Period E5", "E5"));
break;
}
}
}
}
void myButton_Click(object sender, EventArgs e)
{
PeriodID = myDropDownList.SelectedValue.ToString();
}
[ConnectionConsumer("Contract ID Consumer", "ContractIDConsumer")]
public void ContractIDConsumer(IContractID Provider)
{
_myProvider = Provider;
}
[ConnectionProvider("Period ID Provider", "PeriodIDProvider")]
public IPeriodID PeriodIDProvider()
{
return this;
}
}
}
Display
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace ConnectingWebParts.DisplayWebPart
{
[ToolboxItemAttribute(false)]
public class DisplayWebPart : WebPart
{
private IPeriodID _myProvider;
private Label myLabel;
protected override void CreateChildControls()
{
Controls.Clear();
myLabel = new Label();
myLabel.Text = "SELECT A PERIOD";
Controls.Add(myLabel);
}
protected override void OnPreRender(EventArgs e)
{
EnsureChildControls();
if (_myProvider != null)
{
myLabel.Text = _myProvider.PeriodID;
}
else
{
myLabel.Text = "SELECT A PERIOD";
}
}
[ConnectionConsumer("Period ID Consumer", "PeriodIDConsumer")]
public void PeriodIDConsumer(IPeriodID Provider)
{
_myProvider = Provider;
}
}
}IContractID
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConnectingWebParts
{
public interface IContractID
{
string ContractID { get; set; }
}
}
IPeriodID
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConnectingWebParts
{
public interface IPeriodID
{
string PeriodID { get; set; }
}
}
Now when I have a page with all three and I access it with a Read Only user here is what happens.
In other words it's like the selection/property of the StringProvider won't stick for a user with Read Only rights. It works if I create a copy of the Read Only permission and only add the permission "Add and Customize Pages" (which also apparently forces the selection of "Browse Directories") and assign the user that right.
So my question is, is this the proper behaviour or am I doing something wrong in my web parts? Should a read only user be able to have their drop down selections/properties remembered?
Any insight is appreciated.