Hello,
Here's a simple version of what I have:
protected PlaceHolder myph;
public int MyProperty
{
get
{
if( ViewState["myprop"] == null )
ViewState["myprop"] = 1;
return Int32.Parse(ViewState["myprop"].ToString());
}
set { ViewState["myprop"] = value; }
}
override protected void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
for(int i=1;i<=MyProperty;i++)
AddControl(i);
}
private void Page_Load( Object source, System.EventArgs e )
{
if( !IsPostBack)
{
AddControl(MyProperty);
}
}
protected void AddControl(int ID)
{
TextBox mytxt = new TextBox();
Button mybtn = new Button();
mytxt.ID = "textbox" + ID.ToString();
myph.Controls.Add(mytxt);
mybtn.ID = "button" + ID.ToString();
mybtn.Text = "And";
mybtn.Click+=new System.EventHandler(this.btnClick);
myph.Controls.Add(mybtn);
}
protected void btnClick(object source, EventArgs e)
{
MyProperty++;
}
Ok so as you can see what I'm doing is just creating text boxes and buttons dynamically. What I want to do is when the user clicks the button another textbox appears on the webform with a button allowing them to do it again.
What's happening here is that on the first click of the and button nothing happens on the postback. On the second click though things start to work right. How can I make it so on the first postback another textbox and button appear.
Good Luck,
--ghesse
Here's a simple version of what I have:
protected PlaceHolder myph;
public int MyProperty
{
get
{
if( ViewState["myprop"] == null )
ViewState["myprop"] = 1;
return Int32.Parse(ViewState["myprop"].ToString());
}
set { ViewState["myprop"] = value; }
}
override protected void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
for(int i=1;i<=MyProperty;i++)
AddControl(i);
}
private void Page_Load( Object source, System.EventArgs e )
{
if( !IsPostBack)
{
AddControl(MyProperty);
}
}
protected void AddControl(int ID)
{
TextBox mytxt = new TextBox();
Button mybtn = new Button();
mytxt.ID = "textbox" + ID.ToString();
myph.Controls.Add(mytxt);
mybtn.ID = "button" + ID.ToString();
mybtn.Text = "And";
mybtn.Click+=new System.EventHandler(this.btnClick);
myph.Controls.Add(mybtn);
}
protected void btnClick(object source, EventArgs e)
{
MyProperty++;
}
Ok so as you can see what I'm doing is just creating text boxes and buttons dynamically. What I want to do is when the user clicks the button another textbox appears on the webform with a button allowing them to do it again.
What's happening here is that on the first click of the and button nothing happens on the postback. On the second click though things start to work right. How can I make it so on the first postback another textbox and button appear.
Good Luck,
--ghesse