Hallo,
> 
> Jo du hast schon recht...nur wo?;-)

da wo Andreas sagte ;-)

die ID ist der Schl�ssel

Gruss

Alex

hier die L�sung:

WebForm1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" 
Inherits="DotNetFu.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5";>
  </HEAD>
  <body MS_POSITIONING="GridLayout">
        
    <form id="Form1" method="post" runat="server">
<asp:PlaceHolder ID="ph1" Runat="server"/>
<asp:Button id="Button1" runat="server" Text="Button 1"></asp:Button>
<asp:Button id="Button2" runat="server" Text="Button2"></asp:Button>
     </form>
        
  </body>
</HTML>


WebForm1.aspx.cs:
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>
        /// Zusammenfassung f�r WebForm1.
        /// </summary>
        public class WebForm1 : System.Web.UI.Page
        {
                protected System.Web.UI.WebControls.PlaceHolder ph1;
                protected System.Web.UI.WebControls.Button Button2;
                protected System.Web.UI.WebControls.Button Button1;

        

                private void Page_Load(object sender, System.EventArgs e)
                {
                        if(!Page.IsPostBack)
                                ViewState["clicked"] = false;
                        if(Page.IsPostBack&&(bool)ViewState["clicked"]==true)
                        {
                                PlaceHolder ph1 = (PlaceHolder)Page.FindControl("ph1");
                                switch((int)ViewState["Button"])
                                {
                                        case 1:
                                                WebUserControl1 wus1 = 
(WebUserControl1)Page.LoadControl("WebUserControl1.ascx");
                                                ph1.Controls.Clear();
                                                wus1.ID = "wus1";
                                                ph1.Controls.Add(wus1);
                                                break;
                                        case 2:
                                                ph1.Controls.Clear();
                                                WebUserControl2 wus2 = 
(WebUserControl2)Page.LoadControl("WebUserControl2.ascx");
                                                wus2.ID = "wus2";
                                                ph1.Controls.Add(wus2);
                                                break;
                                }
                        }
                }

                #region Vom Web Form-Designer generierter Code
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: Dieser Aufruf ist f�r den ASP.NET Web 
Form-Designer erforderlich.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                /// Erforderliche Methode f�r die Designerunterst�tzung. 
                /// Der Inhalt der Methode darf nicht mit dem Code-Editor ge�ndert 
werden.
                /// </summary>
                private void InitializeComponent()
                {    
                        this.Button1.Click += new 
System.EventHandler(this.Button1_Click);
                        this.Button2.Click += new 
System.EventHandler(this.Button2_Click);
                        this.Load += new System.EventHandler(this.Page_Load);

                }
                #endregion

                public void Button1_Click(object sender, System.EventArgs e)
                {
                        PlaceHolder ph1 = (PlaceHolder)Page.FindControl("ph1");
                        WebUserControl1 wus1 = 
(WebUserControl1)Page.LoadControl("WebUserControl1.ascx");
                        wus1.ID = "wus1";
                        ph1.Controls.Clear();
                        ph1.Controls.Add(wus1);
                        ViewState["clicked"] = true;
                        ViewState["Button"] = 1;
                }

                private void Button2_Click(object sender, System.EventArgs e)
                {
                        PlaceHolder ph1 = (PlaceHolder)Page.FindControl("ph1");
                        WebUserControl2 wus2 = 
(WebUserControl2)Page.LoadControl("WebUserControl2.ascx");
                        wus2.ID = "wus2";
                        ph1.Controls.Clear();
                        ph1.Controls.Add(wus2);
                        ViewState["clicked"] = true;
                        ViewState["Button"] = 2;                
                }
        }
}


WebUserControl1.ascx.cs:
namespace DotNetFu
{
        using System;
        using System.Data;
        using System.Drawing;
        using System.Web;
        using System.Web.UI.WebControls;
        using System.Web.UI.HtmlControls;

        /// <summary>
        ///             Zusammenfassung f�r WebUserControl1.
        /// </summary>
        public class WebUserControl1 : System.Web.UI.UserControl
        {
                protected System.Web.UI.WebControls.Label Label1;

                private void Page_Init(object sender, System.EventArgs e)
                {
                        AddButtons();
                }

                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);
                        }
                }

                        private void btnOption_Command(object sender, CommandEventArgs 
e)
                        {
                                Response.Write("Control1 : Hallo " + 
e.CommandArgument.ToString());
                        }       

                #region Vom Web Form-Designer generierter Code
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: Dieser Aufruf ist f�r den ASP.NET Web 
Form-Designer erforderlich.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                ///             Erforderliche Methode f�r die Designerunterst�tzung
                ///             Der Inhalt der Methode darf nicht mit dem Code-Editor 
ge�ndert werden.
                /// </summary>
                private void InitializeComponent()
                {
                        this.Load += new System.EventHandler(this.Page_Load);
                        this.Init += new System.EventHandler(this.Page_Init);

                }
                #endregion
        }
}

WebUserControl2.ascx.cs:
namespace DotNetFu
{
        using System;
        using System.Data;
        using System.Drawing;
        using System.Web;
        using System.Web.UI.WebControls;
        using System.Web.UI.HtmlControls;

        /// <summary>
        ///             Zusammenfassung f�r WebUserControl2.
        /// </summary>
        public class WebUserControl2 : System.Web.UI.UserControl
        {
                protected System.Web.UI.WebControls.Label Label1;

                private void Page_Init(object sender, System.EventArgs e)
                {
                        AddButtons();
                }


                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);
                        }
                }

                private void btnOption_Command(object sender, CommandEventArgs e)
                {
                        Response.Write("Control2: Hallo " + 
e.CommandArgument.ToString());
                }       

                #region Vom Web Form-Designer generierter Code
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: Dieser Aufruf ist f�r den ASP.NET Web 
Form-Designer erforderlich.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                ///             Erforderliche Methode f�r die Designerunterst�tzung
                ///             Der Inhalt der Methode darf nicht mit dem Code-Editor 
ge�ndert werden.
                /// </summary>
                private void InitializeComponent()
                {
                        this.Load += new System.EventHandler(this.Page_Load);
                        this.Init += new System.EventHandler(this.Page_Init);

                }
                #endregion
        }
}


_______________________________________________
Asp.net Mailingliste, Postings senden an:
[EMAIL PROTECTED]
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net

Antwort per Email an