none
如何获取前一个页面里UpdatePanel控件里动态添加的TextBox控件的值? RRS feed

  • 问题

  • 主页面里有几个动态生成的Textbox控件,是放在PlaceHolderl控件里的,PlaceHolder外面套着UpdatePanel控件,UpdatePanel外面套着ContentPlaceHolder控件,在后一个页面我该如何取得Textbox的值?

    主页面前台代码:

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    
    <div class = "cablingjisuan">
      <asp:ScriptManager ID="xml" runat ="server"></asp:ScriptManager>
      <asp:UpdatePanel ID="Update1" runat ="server">
      <ContentTemplate>
      <asp:Label ID="LblFloor" AssociatedControlID="TbFloor" Text="此项目共有多少楼层?" runat ="server"></asp:Label>
      <asp:TextBox ID="TbFloor" runat ="server" AutoPostBack="True" ontextchanged="TbFloor_TextChanged" ></asp:TextBox>
      <p class="style1"><em>请输入每层网络点的数量</em></p>
      <hr />
      <asp:PlaceHolder ID="Data" runat="server"></asp:PlaceHolder>
      <hr />
      <p class="style1"><em>请输入每层语音点的数量</em></p>
      <hr />
      <asp:PlaceHolder ID="Voice" runat ="server"></asp:PlaceHolder>
      </ContentTemplate>
      </asp:UpdatePanel>
    

    主页面CS代码:

     protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void TbFloor_TextChanged(object sender, EventArgs e)
        {
          for (int i = 0; i < int.Parse(TbFloor.Text); i++)
          {
            Label lblData = new Label();
            Label lblVoice = new Label();
            TextBox tbData = new TextBox();
            TextBox tbVoice = new TextBox();
            int y = i + 1;
            int num = 6;
    
            lblData.ID = "lblData" + i.ToString();
            lblData.Text = "第" + y.ToString() + "层";
            lblVoice.ID = "lblVoice" + i.ToString();
            lblVoice.Text = "第" + y.ToString() + "层";
            tbData.ID = "tbData" + i.ToString();
            tbVoice.ID = "tbVoice" + i.ToString();
    
            Data.Controls.Add(lblData);
            Data.Controls.Add(tbData);
            if (y % num == 0)
            {
    
              Data.Controls.Add(new LiteralControl("</br>"));
            }
    
            Voice.Controls.Add(lblVoice);
            Voice.Controls.Add(tbVoice);
            if (y % num == 0)
            {
              Voice.Controls.Add(new LiteralControl("</br>"));
            }
          }
    
        }
    
    

    副页面CS代码

        protected void Page_Load(object sender, EventArgs e)
        {
    
          TextBox TbFloor = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("Update1").FindControl("Data").FindControl("tbData1");
          WorkCabling.Text = TbFloor.Text;
        }
    

    但是却我告诉值是空的,为什么??请帮帮我,我已经被困扰好长时间了

    2011年3月3日 7:49

答案