Sep 09, 2012, 8:29 PM
Help with adding dynamic controls with data on click direct event
Hi,
I am going to try my best to describe the problem so that it can be recreated.
ok so basically i have a class that has 4 functions and takes in 3 properties: 1- PageSize, 2- DataSource (a list of Problems: Problem class), 3- a direct event handler which is used by the 1 button in every panel that gets created. there's a 4Th property RowCount which returns DataSource.count
The first function creates a panel to display solutions.
The second creates a panel that display 1 problem and many solutions to that problem using the first function in a panel.(Card Item)
The third creates a panel with accordion layout which will hold all panels created by second method.(Cards)
The fourth uses the second and third method to create and return a list of panels that has number of panels in them(List of cards)
in these 'cards' i have all panels repeated to the amount of rows of data we have, and all data are displayed in controls.
i have attached the class below.
ok so on the main page i have a panel to which these are going to be displayed in card layout, but only when the button is clicked.
i managed to get this to display when the button is clicked, but when i click 'next' button to change active index it does not show next item i noticed that active index is always 0, maybe the panel.render method is doing this?
another problem i have is when i create the controls in the click event and if i click a button that was created dynamically it says it cannot be found, so i also added the code to create the controls in the pageload event, but only when text has been entered in the textbox. This works when i click the dynamically created button but this brings another problem, when i click any other button it causes the controls to be created.
i really need help on whats the best way to add the controls dynamically when the button is clicked, is direct events the correct way?
also i dont know why the panel with card layout always have active index to 0 even though the panels items count is > 0. i used the same way that i have on onather panel and it works, only that panel is created on page_init and not on a click direct event
Please help this is a project on my 3rd year of study IT and its due in a 2 weeks:(
Project code can be found at https://code.google.com/p/dutcrm/
Thanks
MARKUP CODE
I am going to try my best to describe the problem so that it can be recreated.
ok so basically i have a class that has 4 functions and takes in 3 properties: 1- PageSize, 2- DataSource (a list of Problems: Problem class), 3- a direct event handler which is used by the 1 button in every panel that gets created. there's a 4Th property RowCount which returns DataSource.count
The first function creates a panel to display solutions.
The second creates a panel that display 1 problem and many solutions to that problem using the first function in a panel.(Card Item)
The third creates a panel with accordion layout which will hold all panels created by second method.(Cards)
The fourth uses the second and third method to create and return a list of panels that has number of panels in them(List of cards)
in these 'cards' i have all panels repeated to the amount of rows of data we have, and all data are displayed in controls.
i have attached the class below.
ok so on the main page i have a panel to which these are going to be displayed in card layout, but only when the button is clicked.
i managed to get this to display when the button is clicked, but when i click 'next' button to change active index it does not show next item i noticed that active index is always 0, maybe the panel.render method is doing this?
another problem i have is when i create the controls in the click event and if i click a button that was created dynamically it says it cannot be found, so i also added the code to create the controls in the pageload event, but only when text has been entered in the textbox. This works when i click the dynamically created button but this brings another problem, when i click any other button it causes the controls to be created.
i really need help on whats the best way to add the controls dynamically when the button is clicked, is direct events the correct way?
also i dont know why the panel with card layout always have active index to 0 even though the panels items count is > 0. i used the same way that i have on onather panel and it works, only that panel is created on page_init and not on a click direct event
Please help this is a project on my 3rd year of study IT and its due in a 2 weeks:(
Project code can be found at https://code.google.com/p/dutcrm/
Thanks
MARKUP CODE
<%--EMAIL Support Agent--%>
<ext:Panel ID="pnlEmailSupport" runat="server" MinHeight="615" Title="Home" TitleAlign="Center"
Enabled="False" Visible="False">
<LayoutConfig>
<ext:ColumnLayoutConfig ManageOverflow="1" />
</LayoutConfig>
<Items>
<%--LEFT PANEL--%>
<ext:Panel runat="server" ID="pnlLeft" ColumnWidth="0.5" Title="Email Problems" MinHeight="590"
ActiveIndex="0">
<LayoutConfig>
<ext:CardLayoutConfig DeferredRender="True" />
</LayoutConfig>
<%--STATUS BAR--%>
<BottomBar>
<ext:StatusBar ID="sbLeft" runat="server" Padding="5">
<Items>
<ext:Label runat="server" ID="lblPage" />
<ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" />
<ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server" />
<ext:ToolbarSpacer ID="ToolbarSpacer2" runat="server" />
<ext:Label runat="server" ID="lblTotal" />
<ext:Button runat="server" ID="btnPrev" Text="<b>Prev</b>">
<DirectEvents>
<Click OnEvent="BtnPrevClick">
<ExtraParams>
<ext:Parameter Name="index" Value="#{pnlLeft}.items.indexOf(#{pnlLeft}.layout.activeItem)"
Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
<ext:ToolbarSeparator ID="ToolbarSeparator2" runat="server" />
<ext:Button runat="server" ID="btnNext" Text="<b>Next</b>">
<DirectEvents>
<Click OnEvent="BtnNextClick">
<ExtraParams>
<ext:Parameter Name="index" Value="#{pnlLeft}.items.indexOf(#{pnlLeft}.layout.activeItem)"
Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:StatusBar>
</BottomBar>
</ext:Panel>
<%--RIGHT PANEL--%>
<ext:Panel ID="pnlRight2" runat="server" Border="false" ColumnWidth="0.5" MinHeight="590">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<%--TOP RIGHT PANEL--%>
<ext:Panel runat="server" ID="pnlTopRight2" Title="Create Ticket" Icon="TagBlueAdd"
Height="250" BodyPadding="10">
<Items>
<ext:FormPanel runat="server" ID="FormPanel2" Border="false" Padding="5">
<Items>
<ext:TextField runat="server" ID="txtClientId2" InputType="Hidden" />
<ext:TextField runat="server" ID="txtEmployeeId2" InputType="Hidden" />
<ext:TextField runat="server" ID="txtClientName2" FieldLabel="Client Name" AnchorHorizontal="70%" />
<ext:TextField runat="server" ID="txtEmployeeName2" FieldLabel="Employee Name" AnchorHorizontal="70%" />
<ext:TextField runat="server" ID="txtProblemId2" FieldLabel="Problem ID" AnchorHorizontal="70%" />
<ext:TextField runat="server" ID="txtSolutionId2" FieldLabel="Solution ID" AnchorHorizontal="70%" />
<ext:ComboBox runat="server" ID="cmbPriority2" FieldLabel="Priority" AnchorHorizontal="40%" />
</Items>
<Buttons>
<ext:Button runat="server" ID="btnCreateTicket2" Text="Create Ticket" Padding="5"
Margins="0 5 0 0" Icon="Disk">
</ext:Button>
</Buttons>
</ext:FormPanel>
</Items>
</ext:Panel>
<%--BOTTOM RIGHT PANEL--%>
<ext:Panel runat="server" ID="pnlBottomRight2" Title="Search For Solution" MinHeight="340"
Icon="BookMagnify" Border="false">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<ext:Panel runat="server" ID="pnlSearch2" Height="50">
<LayoutConfig>
<ext:HBoxLayoutConfig Align="Middle" />
</LayoutConfig>
<Items>
<ext:TextField runat="server" ID="txtProblemSearch2" Width="450" FieldLabel="Description"
Margins="0 0 0 15" />
<ext:Button runat="server" ID="btnProbSearch2" Text="Search" Icon="Magnifier" OnDirectClick="BtnProbSearch2Click"
Margins="0 0 0 10" />
</Items>
</ext:Panel>
<ext:Panel runat="server" ID="pnlProblemSolution2" ActiveIndex="1" MinHeight="507">
<LayoutConfig>
<ext:CardLayoutConfig DeferredRender="True"/>
</LayoutConfig>
<%--STATUS BAR--%>
<BottomBar>
<ext:StatusBar ID="sbRight" runat="server" Padding="5">
<Items>
<ext:Label runat="server" ID="lblPage2" />
<ext:ToolbarSpacer runat="server" />
<ext:ToolbarSeparator runat="server" />
<ext:ToolbarSpacer runat="server" />
<ext:Label runat="server" ID="lblTotal2" />
<ext:Button runat="server" ID="btnPrev2" Text="<b>Prev</b>">
<DirectEvents>
<Click OnEvent="BtnPrev2Click">
<ExtraParams>
<ext:Parameter Name="index2" Value="#{pnlProblemSolution2}.items.indexOf(#{pnlProblemSolution2}.layout.activeItem)"
Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
<ext:ToolbarSeparator ID="ToolbarSeparator4" runat="server" />
<ext:Button runat="server" ID="btnNext2" Text="<b>Next</b>">
<DirectEvents>
<Click OnEvent="BtnNext2Click">
<ExtraParams>
<ext:Parameter Name="index2" Value="#{pnlProblemSolution2}.items.indexOf(#{pnlProblemSolution2}.layout.activeItem)"
Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:StatusBar>
</BottomBar>
</ext:Panel>
</Items>
</ext:Panel>
</Items>
</ext:Panel>
CODE BEHIND#region Right Panel
protected void BtnProbSearch2Click(object sender, DirectEventArgs e)
{
try
{
if (txtProblemSearch2.Text != string.Empty)
{
//create status variables for email problems
int totalProblems;
var cards = new ProblemSolutionGui
{
PageSize = 3,
DataSource = new ProblemBl().GetProblems(txtProblemSearch2.Text),
BtnAcceptClick = BtnAcceptClick
}.CreateListOfCardPanels(out totalProblems, out _totalPagesForProbSol);
pnlProblemSolution2.Items.Add(cards);
sbRight.DefaultText = "<b>Total Problems: " + totalProblems + "</b>";
lblPage2.Html = "<b>Page " + 1 + " of " + _totalPagesForProbSol + "</b>";
pnlProblemSolution2.Render();
}
}
catch (Exception ex)
{
ExtNet.Msg.Alert("Error", ex.Message).Show();
}
}
private static void BtnAcceptClick(object sender, DirectEventArgs directEventArgs)
{
throw new NotImplementedException();
}
protected void BtnNext2Click(object sender, DirectEventArgs e)
{
try
{
var index = int.Parse(e.ExtraParams["index2"]);
if ((index + 1) < pnlProblemSolution2.Items.Count)
{
pnlProblemSolution2.ActiveIndex = index + 1;
}
//show current page
lblPage2.Html = "<b>Page " + (pnlProblemSolution2.ActiveIndex + 1) + " of " + _totalPagesForProbSol + "</b>";
CheckButtons2();
}
catch (Exception ex)
{
ExtNet.Msg.Alert("Error", ex.Message).Show();
}
}
protected void BtnPrev2Click(object sender, DirectEventArgs e)
{
try
{
var index = int.Parse(e.ExtraParams["index2"]);
if ((index - 1) >= 0)
{
pnlProblemSolution2.ActiveIndex = index - 1;
}
//show current page
lblPage2.Html = "<b>Page " + (pnlProblemSolution2.ActiveIndex + 1) + " of " + _totalPagesForProbSol + "</b>";
CheckButtons2();
}
catch (Exception ex)
{
ExtNet.Msg.Alert("Error", ex.Message).Show();
}
}
private void CheckButtons2()
{
try
{
var index = pnlProblemSolution2.ActiveIndex;
btnNext2.Disabled = index == (pnlProblemSolution2.Items.Count - 1);
btnPrev2.Disabled = index == 0;
}
catch (Exception ex)
{
ExtNet.Msg.Alert("Error", ex.Message).Show();
}
}
#endregion