Hi,
I know that the problem its cause the onclick method its after the on
init, due this i have to click twice to see it working...
I would need to know how to add controls dinamically into a page,
mantaining the state of each control during each post-back, and (still
more difficult), each control that i add dinamically has controls that
makes posts-backs...
Could you give me some advices about it?
I will post the code i have here:
************************************************** *
*********************ASPX.cs FILE*********************
************************************************** *
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 ASPX
{
/// <summary>
/// Summary description for MemoryBattery.
/// </summary>
public class MemoryBattery : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder Exercise;
protected Exercise1 Exercise1_=new Exercise1();
protected Exercise2 Exercise2_=new Exercise2();
private void Page_Load(object sender, System.EventArgs e)
{
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load +=new EventHandler(Page_Load);
if(Page.Session["Exercise"]!=null)
{
switch(Page.Session["Exercise"].ToString())
{
case "Exercise2.ascx":
Exercise2_=(Exercise2)LoadControl("Exercise2.ascx" );
Exercise.Controls.Add(Exercise2_);
break;
}
}
else
{
Exercise1_=(Exercise1)LoadControl("Exercise1.ascx" );
Exercise.Controls.Add(Exercise1_);
}
}
}
}
*********************************************
**************END OF THE ASPX.cs****************
********************************************
*********************************************
**************Exercise1.ascx ***************
********************************************
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class Exercise1 : System.Web.UI.UserControl
{
protected Button Button1;
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
private void Button1_Click(object sender, EventArgs e)
{
//******this click its my problem, i would like that when
//the user clicks in this button, order to the aspx to
//load another control**********
Page.Session.Add("Exercise", "Exercise2.ascx");
}
}
************************************************
***************End Exercise1.ascx *****************
************************************************
Thanks.
Kind Regards.
Josema.
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!