不能解决只好再发了,谢谢
是这样的,我先出一个文本框和一个添加按钮,然后点击添加按钮就加一个文本框,可是怎么搞也只能出一个,点击事件只有一次有效,也就是说只能添加一个,怎么办?
页面代码:
<input id="Text1" type="text" runat="server" value="01" />
<asp:PlaceHolder ID="phlYjfx" runat="server"></asp:PlaceHolder>
<asp:Button ID="btnAdd" runat="server" OnClick="Add_Click" Text="继续添加" BackColor="#404040" />
后台代码
public partial class admin_ZyAdd : System.Web.UI.Page
{
int i = 1;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Add_Click(object sender, EventArgs e)
{
i++;
TextBox txtYjfx = new TextBox();
txtYjfx.ID = "txt" + i;
phlYjfx.Controls.Add(txtYjfx);
}
}
}
{
}
if(ViewState("i")!=null)然后这个就提示错误,不明白!
Compiler Error Message: CS0118: 'System.Web.UI.Control.ViewState' is a 'property' but is used like a 'method'Source Error: Line 20: protected void Add_Click(object sender, EventArgs e)
Line 21: {
Line 22: if (ViewState("i") == null)
Line 23: {
Line 24: string strYjfx = "<input name='txt" + i + "' type='text' runat='server' id='txt" + i + "' />";
Source File: f:\site\enroll\admin_zyAdd.aspx.cs Line: 22
{}
改为:static int i = 1;
ViewState["i"]=1;
这样的语句行否?它怎么改变自己的值呢?学艺不精,请多指教!
这个方法我试过过的,关键是动态添加的只能是html控件, 一加上runnat=server就出错,
不好在后台里把它的值取出来,比如Request.Forms,就不行