Hello,
Well, you can take advantage of
CMS.GlobalHelper.RequestStockHelper class which gives you ability to insert and get items into
HttpContext.Current.Items collection using
Add/GetItem methods. You can add a reference to a web part to the collection and retrieve it in the code of another web part. I will give you a simple example.
Let’s assume that I have two web parts (WebPartA and WebPartB) and I want to change the Visible property of the WebPartB fromt the code behind of the WebPartA.
WebPartA contains a button:
<asp:Button runat="server" ID="btn" OnClick="btn_Click" />In the OnClick handler I want to change the Visible property of the WebPartB.
First, you need to add the WebPartB web part into the RequestStockHelper collection. You can do so in the OnInit method of the WebPartB:
protected override void OnInit(EventArgs e)
{
CMS.GlobalHelper.RequestStockHelper.Add("WebPartB", this);
base.OnInit(e);
}
Now you can access the WebPartB in the OnClick handler of the WebPartA and change its Visible (or any other) property:
protected void btn_Click(object sender, EventArgs e)
{
CMSAbstractWebPart WebPartB = CMS.GlobalHelper.RequestStockHelper.GetItem("WebPartB") as CMSAbstractWebPart;
if (something)
{
WebPartB.Visible = false;
}
}
I hope this makes sense to you.
If you need more information about RequestStockHelper class please take a look at API reference:
Kentico CMS APIBest regards,
Michal Legen