1个回答
2013-07-24
展开全部
如:HTML code <asp:PlaceHolder ID="PlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
C# code protected void Button1_Click(object sender, EventArgs e)
{
string result = string.Empty;
foreach( Control ctrl in PlaceHolder1.Controls )
{
if (ctrl.GetType () == typeof (TextBox))
{
TextBox tb = ctrl as TextBox;
result = result + "," + tb.Text;
}
}
if (result.Length > 0)
{
this.Label1.Text = result.Substring(1);
}
}//添加事件C# code private void AddBlurAttribute(Control cntrl)
{
if (cntrl.Controls.Count > 0)
{
foreach (Control childControl in cntrl.Controls)
{
AddBlurAttribute(childControl);
}
}
if (cntrl.GetType() == typeof(TextBox))
{
TextBox tb = (TextBox)cntrl;
tb.Attributes.Add("onBlur", ".....");
}
}
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
C# code protected void Button1_Click(object sender, EventArgs e)
{
string result = string.Empty;
foreach( Control ctrl in PlaceHolder1.Controls )
{
if (ctrl.GetType () == typeof (TextBox))
{
TextBox tb = ctrl as TextBox;
result = result + "," + tb.Text;
}
}
if (result.Length > 0)
{
this.Label1.Text = result.Substring(1);
}
}//添加事件C# code private void AddBlurAttribute(Control cntrl)
{
if (cntrl.Controls.Count > 0)
{
foreach (Control childControl in cntrl.Controls)
{
AddBlurAttribute(childControl);
}
}
if (cntrl.GetType() == typeof(TextBox))
{
TextBox tb = (TextBox)cntrl;
tb.Attributes.Add("onBlur", ".....");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询