cs:
private Label label = new Label();

    
private TextBox textbox = new TextBox();

    
private void Page_Load(object sender, System.EventArgs e)
    
{

       
// 在此处放置用户代码以初始化页面

        Table tb 
= new Table();//创建一个表格

        tb.BorderWidth 
= Unit.Parse("1");

        tb.Width 
= Unit.Parse("100%");

        
for (int j = 0; j < 2; j++)
        
{

            TableRow tr 
= new TableRow();//创建一行

            TableCell cell1 
= new TableCell();//创建单元格,也就是第一列

            cell1.Text 
= j.ToString()+"yyy";//设置单元格内的文本

            tr.Cells.Add(cell1);
//添加到行中

            TableCell cell2 
= new TableCell();//创建第二列

            cell2.Text 
= (j * j*7).ToString();

            tr.Cells.Add(cell2);

            tb.Rows.Add(tr);
//添加到表格中



        }

        
this.b.Controls.Add(tb);
   
        
/////////////////////////////////////////

        textbox.Text 
= "输入结束后请按TAB键";//程序运行时文本框内的提示文本

        textbox.ID 
= "t";//给文本框起个名字

        textbox.Width 
= 200;//设置宽度

        textbox.Height 
= 20;//设置高度

        textbox.AutoPostBack 
= true;//响应事件的条件

        textbox.TextChanged 
+= new EventHandler(textbox_TextChanged);//添加事件,在.net中,按TAB自动生成

        textbox.Attributes.Add(
"onmouseover""t.value=''");//给文本框添加一个javascript事件,当鼠标从文本框中移过时自动清除文本框内的提示内容


         
this.a.Controls.Add(textbox);//添加
        
        
////////////////////////////////////////
       this.a.Controls.Add(label);//此处将标签添加到PlaceHolder中
    }


    
Web 窗体设计器生成的代码
    
private void textbox_TextChanged(object sender, EventArgs e)
    
{
        
this.label.Text = textbox.Text;   //事件响应方法.当文本框失去焦点时将标签设成和文本框同样的内容.
    }

}
aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="test_Default2" %>

<!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>
     
<asp:PlaceHolder id ="a" runat ="server"></asp:PlaceHolder>
     
     
<br/>
     
<hr />
     
<asp:PlaceHolder ID = "b" runat ="server"></asp:PlaceHolder>
    
</div>
    
</form>
</body>
</html>
结果:

posted on 2006-12-09 16:49  ipusr  阅读(518)  评论(1)    收藏  举报