.net を開始し、動的に複数のテキスト ボックスを作成します。
私はこれを書いています:
<%@ 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>
この
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);
}
}
}
Button1 を 2 回クリックすると、テキスト ボックスが 1 つしか表示されない理由がわかりません。
なぜこの動作ですか?私がやりたいことをする良い方法は何ですか?前もって感謝します