Dobrý den, mám problém s dynamicky generovanými linkbuttony. Jejich přiřazené eventy se nespouštějí. ASPX:
<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<form id="AspNetWebForm1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
</form>
</div>
</body>
</html>
CSharp:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private string Path = "";
protected void Page_Load(object sender, EventArgs e)
{
foreach (DirectoryInfo Folder in new DirectoryInfo("D:/").GetDirectories())
{
LinkButton NameCtl = new LinkButton
{
Text = Folder.Name
};
NameCtl.ID = NameCtl.ClientID;
NameCtl.Click += new EventHandler(NameCtl_Click);
Panel1.Controls.Add(NameCtl);
}
//if (!this.IsPostBack)
{
this.TextBox1.Text = this.Path;
}
}
private void NameCtl_Click(object sender, EventArgs e)
{
this.Path += ((LinkButton)sender).Text;
}
}
Nevíte jak tento problém vyřešit? Děkuji
|