I begin .net and to start I will create dynamically multiple textbox.
I have write this :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Page sans titre</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="OnclickButton" />
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
</form>
</body>
</html>
and this
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void OnclickButton(object sender, EventArgs ea)
{
Random random = new Random();
int randomNumber = random.Next(0, 100);
Button btnSomeButton = sender as Button;
btnSomeButton.Text = "I was clicked!" + randomNumber;
TextBox txt = new TextBox();
txt.ID = "txt_" + randomNumber;
form1.Controls.Add(txt);
}
}
}
I don't understand why when I click 2 time on Button1 only 1 Text Box appears.
Why this behavior? What is the good way to do what I want? thank you in advance