Also zuerst einmal ein herzliches Dankesch�n an alle die mir hier helfen, insbesondere Alex und Rene;-)
Eure Beispiele funktionieren tats�chlich, also hab ich mich an das Problem
herangetastet:
In der aspx-Seite habe ich einen Button, welcher bei Click das UserControl
l�dt. (Das habe ich ungewollt dummerweise verschwiegen)
private void Button1_Click(object sender, System.EventArgs e)
{
WebUserControl1 wuc = (WebUserControl1)LoadControl("WebUserControl1.ascx");
Panel1.Controls.Add(wuc);
}
Das UserControl wird auch ohne Probleme geladen...aber jetzt ist fertig mit
Event-Handling...:-( Eure Beispiele funktionieren dann auch nicht mehr
(siehe Attachment)
Gruss Daniel
-----Urspr�ngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im
Auftrag von Alexander Zeitler
Gesendet: Donnerstag, 18. M�rz 2004 11:40
An: [EMAIL PROTECTED]
Betreff: RE: [Asp.net] User Control & Events
Hallo,
>
> Dieses Ph�nomen kenne ich auch.
> Macht man des dynamische Erstellen der Buttons im PageLoad() dann geht es.
> Sobald man seine eigene Methode daf�r schreibt geht es nicht mehr.
>
Du meinst sowas?
private void Page_Load(object sender, System.EventArgs e)
{
AddButtons();
}
private void AddButtons()
{
for(int i=1;i<10;i++)
{
LinkButton btnOption = new LinkButton();
btnOption.Text = "Mein Button " +
i.ToString();
btnOption.ID = "btnOption_" + (i).ToString()
;
btnOption.CommandArgument = (i).ToString();
btnOption.Command +=new
CommandEventHandler(btnOption_Command);
Literal l = new Literal();
l.Text = "<br>";
this.Controls.Add(btnOption);
this.Controls.Add(l);
if(!Page.IsPostBack)
{
btnOption.Command +=new
CommandEventHandler(btnOption_Command);
}
//lblOptions.Controls.Add(btnOption);
//lblOptions.Controls.Add(l);
}
}
funktioniert hier auch reibungslos
Gruss
Alex
_______________________________________________
Asp.net Mailingliste, Postings senden an:
[EMAIL PROTECTED]
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net
WebForm1.aspx
Description: Binary data
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace DotNetFu
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel Panel1;
private void Page_Load(object sender, System.EventArgs e)
{
//LoadMyControl();
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new
System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
WebUserControl1 wuc =
(WebUserControl1)LoadControl("WebUserControl1.ascx");
Panel1.Controls.Add(wuc);
}
}
}
WebForm1.aspx.resx
Description: Binary data
