السلام عليكم ورحمة الله وبركاتة
انا عندى مشكلة فى بناء text box controlاثناء الruntime . الى بيحصل ان عندما اعمل click on button يضيف اول مرة وتانى مرة ولاكان بعد كدا لايضيف اى تانى
الكود:
public partial class _Default : System.Web.UI.Page
{
TextBox t;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
if (ViewState["mode"].ToString() == "1")
{
//this.RegisterStartupScript("", "<scrip>" + "alert('" + t.Text + "');</script>");
// Response.Write(Request.Form["t"].ToString());
}
}
else
{
ViewState.Add("mode", "0");
}
}
#region web form designer generated code
protected override 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);
}
#endregion
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if (ViewState["mode"].ToString() == "1")
{
Creattextbox();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Creattextbox();
ViewState.Add("mode","1");
//Controls.Add(new LiteralControl("<br/>"));
}
private void Creattextbox()
{
t = new TextBox();
Panel1.Controls.Add(t);
t.ID = "txt";
// Controls.Add(new LiteralControl("<br/>"));
}
}والكود موجود فى المرفق
ياريت حد يحليلى المشكلة دى ضرورى
السلام عليكم ورحمة الله وبركاتة