So, my problem is that in this case I would like to update my repeater when I click on each button but I want them to do different functions so I pass the EventHandlers to my Update function. Unfortunately, after the panel gets updated once, panel returns back to it's previous state and my button's event doesn't fire.In this case, RepeaterMinorControl_Click does get called but the buttons' events don't fire after that. Each button does an AsyncPostback.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="10G.aspx.cs" Inherits="OEDUY.Grades._10._10G" ClientIDMode="AutoID" %>
<!DOCTYPE html>
<html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)">
<head runat="server">
<title></title>
<link rel="stylesheet" href="../../FormsStyleSheets/StyleSheets/10G.css" />
</head>
<body>
<form id="form1" runat="server">
<div class="titleDiv">
<span></span>
</div>
<asp:ScriptManager runat="server" ID="scriptManager"></asp:ScriptManager>
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePFB">
<ContentTemplate>
<asp:Repeater runat="server" ID="buttonRepeater">
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="buttonRepeater" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
This is the C# code:
string mainPath;
string currentMinorKey;
string currentLessonKey;
string currentSeasonKey;
protected void Page_Load(object sender, EventArgs e)
{
mainPath = Context.Request.MapPath("~");
string[] dirs = Core.Core.DirectoryController.GetSubDirectories($"{mainPath}Grades\\10");
var req = Request.Form;
FillButtonRepeater(dirs, new Action<object, EventArgs>(RepeaterMinorControl_Click));
}
protected void FillButtonRepeater(string[] Values, Action<object, EventArgs> ButtonAction)
{
buttonRepeater.Controls.Clear();
foreach (string item in Values)
{
Button control = new Button() { Text = Core.Core.DirectoryNameController.GetValue(item), CssClass = "btns", ID = $"{item}btn", UseSubmitBehavior = false };
control.Click += ButtonAction.Invoke;
buttonRepeater.Controls.Add(control);
}
}
private void RepeaterMinorControl_Click(object sender, EventArgs e)
{
currentMinorKey = Core.Core.DirectoryNameController.GetKey((sender as Button).Text);
string[] dirs = Core.Core.DirectoryController.GetSubDirectories($"{mainPath}Grades\\10\\{currentMinorKey}");
FillButtonRepeater(dirs, new Action<object, EventArgs>(RepeaterLessonControl_Click));
}
private void RepeaterLessonControl_Click(object sender, EventArgs e)
{
currentLessonKey = (sender as Button).Text;
string[] dirs = Core.Core.DirectoryController.GetSubDirectories($"{mainPath}Grades\\10\\{currentMinorKey}\\{currentLessonKey}");
FillButtonRepeater(dirs, new Action<object, EventArgs>(RepeaterSeasonControl_Click));
}
private void RepeaterSeasonControl_Click(object sender, EventArgs e)
{
currentSeasonKey = Core.Core.DirectoryNameController.GetKey((sender as Button).Text);
string[] dirs = Core.Core.DirectoryController.GetSubDirectories($"{mainPath}Grades\\10\\{currentMinorKey}\\{currentLessonKey}\\Seasons\\{currentSeasonKey}");
FillButtonRepeater(dirs, new Action<object, EventArgs>(RepeaterControlDirectory_Click));
}
private void RepeaterControlDirectory_Click(object sender, EventArgs e)
{
}
Aucun commentaire:
Enregistrer un commentaire