how to fire a event to my dynamic created textboxes?

S

Satish

hi,
how to fire a event to my dynamic created textboxes?...say all buttons
will inturn call a same method...say sayhi()?
here is my code...
Thanks in advance.
-Satish



ASPX
~~~~

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="dyna.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<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 MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 39px; POSITION:
absolute; TOP: 61px" runat="server">enter no of textbox to
create</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 46px;
POSITION: absolute; TOP: 91px" runat="server"></asp:TextBox>
<asp:placeHolder id="PlaceHolder1"
runat="server"></asp:placeHolder>
<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 225px;
POSITION: absolute; TOP: 94px" runat="server"
Text="Create"></asp:Button>
</form>
</body>
</HTML>


Behind the code
~~~~~~~~~~~~~~~
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 dyna
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here


}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
int i;
int count=Int32.Parse(TextBox1.Text);
for(i=0;i<count;i++)
{
Button str = new Button();
str.ID = "box"+i.ToString() ;
//this.FindControl("Form1").Controls.Add(str);
PlaceHolder1.Controls.Add(str);
}
}

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top