Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Have searched google but not found anything usefull so i will try here.
I have a usercontrol which renders X forms.
email = new TextBox() { ID = "email"+node.Id }; Panel1.Controls.Add(email); message = new TextBox() { ID = "message" + node.Id }; Panel1.Controls.Add(message); ImageButton button = new ImageButton() { ID = "button" + node.Id, CommandArgument = node.Id.ToString()+"~~"+email.Text+"~~"+message.Text, }; Panel1.Controls.Add(button); button.Command += new CommandEventHandler(button_Command);
The Click event only works for the last form added to the Panel?
Can i name ImageButton dynamic.. like ImageButton "button"+node.Id and the have an click event for that button?
ImageButton "button"+node.Id does'nt work.. any idea to where to go from here?
Appriciate any help :)
Have made a simple test. Hope it's simpler to see what i want to do.
using System;using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public TextBox txt;
protected void Page_Load(object sender, EventArgs e)
for (int i = 0; i < 10; i++)
TextBox txt = new TextBox() {
Text = "Text"+i
};
Panel1.Controls.Add(txt);
Button btn = new Button()
Text = "Button" + i
Panel1.Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
Button clicked = (Button)sender;
Response.Write("You have clicked button " + clicked.Text);
Response.Write("Value of corresponding textbox ?? WHAT TO PUT HERE???? = ");
Found a solution that i can live with.. but there have to be a better way..
using System;
using System.Web.UI.WebControls;
Text = "Text"+i,
ID = "txt"+i
txt = new TextBox()
Text = "sdfsdfsdf",
ID = "msg" + i
Text = "Button" + i,
CommandArgument = i.ToString()
btn.Command += new CommandEventHandler(btn_Command);
void btn_Command(object sender, CommandEventArgs e)
TextBox txt = (TextBox)FindControl("txt" + e.CommandArgument.ToString());
Response.Write("Value of textbox"+txt.Text);
txt = (TextBox)FindControl("msg" + e.CommandArgument.ToString());
Response.Write("Value of msg" + txt.Text);
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Usercontrol with dynamic buttons + click events
Have searched google but not found anything usefull so i will try here.
I have a usercontrol which renders X forms.
email = new TextBox()
{
ID = "email"+node.Id
};
Panel1.Controls.Add(email);
message = new TextBox()
{
ID = "message" + node.Id
};
Panel1.Controls.Add(message);
ImageButton button = new ImageButton()
{
ID = "button" + node.Id,
CommandArgument = node.Id.ToString()+"~~"+email.Text+"~~"+message.Text,
};
Panel1.Controls.Add(button);
button.Command += new CommandEventHandler(button_Command);
The Click event only works for the last form added to the Panel?
Can i name ImageButton dynamic.. like ImageButton "button"+node.Id and the have an click event for that button?
ImageButton "button"+node.Id does'nt work.. any idea to where to go from here?
Appriciate any help :)
Have made a simple test. Hope it's simpler to see what i want to do.
using System;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public TextBox txt;
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
TextBox txt = new TextBox() {
Text = "Text"+i
};
Panel1.Controls.Add(txt);
Button btn = new Button()
{
Text = "Button" + i
};
Panel1.Controls.Add(btn);
btn.Click += new EventHandler(btn_Click);
}
}
void btn_Click(object sender, EventArgs e)
{
Button clicked = (Button)sender;
Response.Write("You have clicked button " + clicked.Text);
Response.Write("Value of corresponding textbox ?? WHAT TO PUT HERE???? = ");
}
}
Found a solution that i can live with.. but there have to be a better way..
using System;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public TextBox txt;
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
TextBox txt = new TextBox() {
Text = "Text"+i,
ID = "txt"+i
};
Panel1.Controls.Add(txt);
txt = new TextBox()
{
Text = "sdfsdfsdf",
ID = "msg" + i
};
Panel1.Controls.Add(txt);
Button btn = new Button()
{
Text = "Button" + i,
CommandArgument = i.ToString()
};
Panel1.Controls.Add(btn);
btn.Command += new CommandEventHandler(btn_Command);
}
}
void btn_Command(object sender, CommandEventArgs e)
{
Button clicked = (Button)sender;
Response.Write("You have clicked button " + clicked.Text);
TextBox txt = (TextBox)FindControl("txt" + e.CommandArgument.ToString());
Response.Write("Value of textbox"+txt.Text);
txt = (TextBox)FindControl("msg" + e.CommandArgument.ToString());
Response.Write("Value of msg" + txt.Text);
}
}
is working on a reply...