|
Dear sir/mam
i have created one button dynamicaly and i want to perform some instrustion when this button is clicked. and also want to maintain session of this page to another page with this button click.
any one can help me??? soon
yogesh
|
|
|
|
|
Ho yougesh,
using Delegation u can easily do it.
Check the following code
protected void Page_Load(object sender, EventArgs e)
{
Button mybtn = new Button();
mybtn.Text = "Dynamic Button";
Panel1.Controls.Add(mybtn);
mybtn.Click += new System.EventHandler(mybtn_Click);
}
public void mybtn_Click(object sender, EventArgs e)
{
Response.Write("You have click on this");
}
Hope this will help you !!!!
|
|
|
|
|
sir actualy, i have created a no of buttons in one page using array of buttons. so wht can i do for it???? thank u sir for that
i hv use this code for click event but it does not work
public void btrequest1[i]_Click(object sender, EventArgs e)
{
Response.Write("You have click on this");
}
yogesh
modified on Monday, December 17, 2007 9:31:09 AM
|
|
|
|
|
Hi yogesh,
Use this one
public partial class _Default : System.Web.UI.Page
{
Button[] b = new Button[10];
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
b[i] = new Button();
b[i].Text = "Dynamic Button " + i.ToString() ;
Panel1.Controls.Add(b[i]);
b[i].Click += new System.EventHandler(mybtn_Click);
}
}
public void mybtn_Click(object sender, EventArgs e)
{
Button mybtn =sender as Button;
Response.Write(mybtn.Text.ToString());
}
}
This will solve your problem !!!
|
|
|
|