动态复选框..values在重新创建时会丢失 [英] Dynamic Check Box ..values are lost when it is recreated
问题描述
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
公共局部类_Default:System.Web.UI.Page
{
int NoOfTextBoxes = 5;
受保护的void Page_Load(对象发送者,EventArgs e)
{
}
受保护的void Button1_Click(对象发送者,EventArgs e)
{
//第一次调用此函数,并在第一时间在此处创建复选框
//在浏览器中输入值之后,然后单击button2(Button2_Click)
//但是当Button2_Click被执行时,值会丢失,因为它们会重新创建...
function_temp();
}
受保护的void Button2_Click(对象发送者,EventArgs e)
{
function_temp();
for(int cou = 1; cou< = NoOfTextBoxes; cou ++)
{
TextBox txt =新的TextBox();
txt =(TextBox)FindControl("text" + cou.ToString());
Response.Write(txt.Text +"
");
}
}
受保护的void function_temp()
{
for(int cou = 1; cou< = NoOfTextBoxes; cou ++)
{
TextBox txt =新的TextBox();
//分配文本框ID
txt.ID ="text" + cou.ToString();
Panel2.Controls.Add(txt);
}
}
但是重新创建时值会丢失..任何帮助!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
int NoOfTextBoxes = 5;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//first time this function is called and check box is its created here for fisrt time
//values are entered after in browserand then button2(Button2_Click) is clicked
//but when Button2_Click is excuted the values are lost as they are again recreate...
function_temp();
}
protected void Button2_Click(object sender, EventArgs e)
{
function_temp();
for (int cou = 1; cou <= NoOfTextBoxes; cou++)
{
TextBox txt = new TextBox();
txt = (TextBox)FindControl("text" + cou.ToString());
Response.Write(txt.Text + "
");
}
}
protected void function_temp()
{
for (int cou = 1; cou <= NoOfTextBoxes; cou++)
{
TextBox txt = new TextBox();
//assigning text box Id
txt.ID = "text" + cou.ToString();
Panel2.Controls.Add(txt);
}
}
but values are lost when it is recreated..Any Help!
推荐答案
感谢您的发帖!我建议将您的问题发布到MS论坛之一中,
首页› 常规ASP .NET » Web表单
位于此处:http://forums.asp.net/18.aspx
这篇关于动态复选框..values在重新创建时会丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!