Jun 28, 2017, 12:05 PM
Passing parameters to UserControl
Hi,
I'm using UserControl in my page like that:
I'm rendering those user controls on page load and also inside direct method (when some button pressed)
the problem:
I want to set the UserControl parameters before it rendered.
I saw that you need to do something like that:
But i dont understand how its works i.e. what i am doing with the string s?
how i am put this user control inside FuelItemsMatrices warpped up in his own container?
I'm using UserControl in my page like that:
foreach (var price in PricesInPriceList)
{
var matrix = new UserControlLoader()
{ Path = "UserControls/FuelPriceUpdateMatrix.ascx", UserControlID = "Matrix" + price.ItemId };
var matrixContainer = new Container();
matrixContainer.Items.Add(matrix);
matrixContainer.AddTo(FuelItemsMatrices);
}
The .aspx looks like that: <ext:Container MarginSpec="10, 20,10,10" Flex="5" ID="FuelItemsMatrices"
runat="server" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="StretchMax" />
</LayoutConfig>
</ext:Container>
I'm rendering those user controls on page load and also inside direct method (when some button pressed)
the problem:
I want to set the UserControl parameters before it rendered.
I saw that you need to do something like that:
MyUserControl uc = (MyUserControl)UserControlRenderer.LoadControl(path);
uc.Property1 = "value1";
var s =ComponentLoader.ToConfig(uc);
return s;
But i dont understand how its works i.e. what i am doing with the string s?
how i am put this user control inside FuelItemsMatrices warpped up in his own container?