js 获取用户控件值,如何获取自动生成的控件的值

如何获取自动生成的控件的值 - 故障解答 - 电脑教程网

如何获取自动生成的控件的值

日期:2007-07-01   荐:
如何获取自动生成的控件的值我编程在表格中放入4个textBox控件,希望点击提交按钮读取前两getextBox中的内容写入后两个texBox中,WebForm1.aspx:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD><title>WebForm1</title><meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"><meta name="CODE_LANGUAGE" Content="C#"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"></HEAD><body><form id="Form1" method="post" runat="server"><FONT face="宋体"><asp:Table id="Table1" style="Z-INDEX: 101; LEFT: 9px; POSITION: absolute; TOP: 8px" runat="server"></asp:Table><br><BR><asp:Button id="Button1" runat="server" Text="提交" Width="87px"></asp:Button></FONT></form></body></HTML>WebForm1.aspx.cs:using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace test{/// <summary>/// WebForm1 的摘要说明。/// </summary>public class WebForm1 : System.Web.UI.Page{protected System.Web.UI.WebControls.Button Button1;protected System.Web.UI.WebControls.Table Table1;private void Page_Load(object sender, System.EventArgs e){// 在此处放置用户代码以初始化页面TableRow tRow = new TableRow();Table1.Rows.Add(tRow);for (int i=1;i<=4;i ){TableCell tCell = new TableCell();TextBox tTextBox = new TextBox();tTextBox.ID="tb" i.ToString();tTextBox.Width=System.Web.UI.WebControls.Unit.Pixel(60);tTextBox.Height=System.Web.UI.WebControls.Unit.Pixel(23);tCell.Controls.Add(tTextBox);tCell.Width=System.Web.UI.WebControls.Unit.Pixel(60); tRow.Cells.Add(tCell);}}#region Web Form Designer generated codeoverride protected void OnInit(EventArgs e){//// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。//InitializeComponent();base.OnInit(e);}/// <summary>/// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。/// </summary>private void InitializeComponent(){ this.Button1.Click = new System.EventHandler(this.Button1_Click);this.Load = new System.EventHandler(this.Page_Load);}#endregionprivate void Button1_Click(object sender, System.EventArgs e){}}}Button1_Click事件该如何写?我搞了半天都没有得到控件中的值。((TextBox)Table1.FindControl("tb3")).Text = ((TextBox)Table1.FindControl("tb1")).Text;((TextBox)Table1.FindControl("tb4")).Text = ((TextBox)Table1.FindControl("tb2")).Text;
标签: