protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
TextBox txt = new TextBox();
txt.ID = "txt0";
td.Controls.Add(txt);
tr.Cells.Add(td);
tabUserDefined.Rows.Add(tr);
}
} protected void Button1_Click(object sender, EventArgs e)
{
TextBox txt = form1.FindControl("txt0") as TextBox;
string ss = txt.Text;
}
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="tabUserDefined" Width="100%" runat="server" CellPadding="1" CellSpacing="1" border="1">
</asp:Table>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
</body>当点击按钮时提示未将对象引用设置到实例,那应该怎么获取TextBox的值呢?
解决方案 »
- 怎么获得客户端机器名?
- 如何做功能“在戴尔网站中 左边选择 购买电脑配置 右边则动态显示价格 ”
- 权限问题页面的重定向问题~~~~~~~ 急急急急急急急急急急急!!!!
- 想请教一下ASP.Net webservice的作用
- VS2005中.aspx文件用浏览器打开没问题,但是如果直接发布iis中,直接用IE就打不开了
- Frame框架拖动问题
- 简单.net Remoting 的应用,怎么总是报错,请各位大侠帮忙指点一下。谢谢。
- 为什么我的事件无法执行了!急!
- 关于使用"freetextbox"流量的问题
- 关于2000pro下安装Studio .Net的问题,郁闷中...
- ASP.NET 博客内容中提取关键字
- 如何打开服务器上的文件
我没看见
改成
txt.name = "txt0";
看行不?
我对asp控件不熟悉。
string ss = txt.Text;=>
string ss = Request.Form["txt0"];
准确的写法应该是 Request.Form[txt0.UniqueID]
txt0 在此不是id ,是取 html 元素的 name
要是有个RadioButton怎么取它的Text属性,怎么判断有没有选中呢?
比如这样protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
TextBox txt = new TextBox();
txt.ID = "txt0";
RadioButton rb = new RadioButton();
rb.ID = "rb";
rb.Text = "a";
td.Controls.Add(txt);
td.Controls.Add(rb);
tr.Cells.Add(td);
tabUserDefined.Rows.Add(tr);
}
}
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
TextBox txt = new TextBox();
txt.ID = "txt0";
td.Controls.Add(txt);
tr.Cells.Add(td);
tabUserDefined.Rows.Add(tr);
{
TableRow tr = new TableRow();
TableCell td = new TableCell();
TextBox txt = new TextBox();
txt.ID = "txt0";
td.Controls.Add(txt);
tr.Cells.Add(td);
tabUserDefined.Rows.Add(tr);
}