各位高手帮看看:为什么我的strArray[0]存入的正确的值,而strArray[1]存入的是"Request.form["text1"],Request.form["text2"]"值?为什么不是Request.form["text2"]的值???
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="RoadShow.Web.WebForm1" %><!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div1">
        <input type="text" name="text1" />
        <a href="javascript:CreateInputTxt();">添加新的text</a><br />
        <asp:Button ID="Button1" runat="server" Text="取值" onclick="Button1_Click" />
    </div>
    <asp:HiddenField ID="Count" runat="server" Value="0" />
    </form>       <script language="javascript" type="text/javascript">
        function CreateInputTxt() {
            document.getElementById("Count").value++;
            j = document.getElementById("Count").value;
            var i = 1;
            if (i < 5) {
                i++;
                div1.innerHTML = div1.innerHTML + "<input type='text' name='text" + i + "' style='width:270px;' MaxLength='20' ><br>";
            }
            if (j > 6) {
                alert("多于6个失败");
            }
        }        
    </script></body>
</html>
后台:::
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace RoadShow.Web
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {        }        protected void Button1_Click(object sender, EventArgs e)
        {
            //获得text的个数
            int i = int.Parse(this.Count.Value);
            //Response.Write(i);
            //定义个数组,用来接受text的值
            string[] strArray = new string[i];
            for (int j = 0; j < i; j++)
            {
                strArray[j] = Request.Form["text" + (j + 1).ToString()];            }
            foreach (string str in strArray)
            {
                //测试strArray里有没有值
                Response.Write(str);
            }
            this.Count.Value = "0";
        }
    }
}