日期:2014-05-17  浏览次数:20459 次

重金求解
问题:Page页面上有二个Button,一个Panel。其中Button1点击的时候,自动在Panel里添加5个文本框。在生成的5个文本框中输入数值后。 点击另外一个Button时候,弹出刚才输入文本框的值。
 
 

------解决方案--------------------
protected void btn1_Click(object sender, EventArgs e)
{
for(int i=0;i<5;i++)
{
TextBox txt = new TextBox(); 
txt.ID = "txt_" + i.ToString(); 
Panel1.Controls.Add(txt); 
}
}

protected void btn2_Click(object sender, EventArgs e)
{
for(int i=0;i<5;i++)
{
TextBox txt=Panel1.FindControl("txt_" + i.ToString()) as TextBox;
if(txt!=null)
{}
}
}
------解决方案--------------------
ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript' defer>alert('" +txt.Text + "');</script>");
------解决方案--------------------
厉害加速度
不愧为答题机器人 呵呵
------解决方案--------------------
因为动态生成的textbox在重新点击按钮后会消失,所以在页面上放置HiddenField1来保存textbox的值

HTML code
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">    
        </asp:Panel>
        <asp:HiddenField ID="HiddenField1" runat="server" />
        <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" OnClientClick="saveValue();" />
<script>
function saveValue()
{
    var obj=document.getElementById("Panel1").getElementsByTagName("input");
    for(var i=0;i<obj.length;i++)
   {
       if(obj.type="text")
                document.getElementById("HiddenField1").value+=obj[i].value+",";
   }  
   alert(document.getElementById("HiddenField1").value)
}
</script>

------解决方案--------------------
我们只能跟随问答机器人后面接点分
SF都让他一个人占领了 速度太快
------解决方案--------------------
我也来凑个热闹,企图获得重金!!
生成一个TextBox,多个依次类推,放一个Hidden1,中间变量

页面html
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" OnClientClick="test()" />
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
<input id="Hidden1" type="hidden" runat="server" />

js:
<script type="text/javascript">
function test() {
document.getElementById("Hidden1").value = document.getElementById("myT1").value;
}
</script>

c#
protected void Button1_Click(object sender, EventArgs e)
{
this.sText();//动态生成TextBox
}
protected void Button2_Click(object sender, EventArgs e)
{
ViewState["t1"] = Hidden1.Value.ToString();//获得中间变量
this.sText();//动态生成TextBox
((TextBox)Panel1.FindControl("myT1")).Text = ViewState["t1"].ToString();//赋值
}

private void sText()
{
TextBox myT1 = new TextBox();
myT1.ID = "myT1";
Panel1.Controls.Add(myT1);
}
------解决方案--------------------
探讨
protected void btn1_Click(object sender, EventArgs e)