linkbuttons dinamically

O

oterox

I've created a method for creating linkbuttons dinamically.It works fine if
the method is in the webform but if i try to put the method in a different
class it doesn't work.I think the problem is in how to pass an object to the
handler:


--- webform1 ----- This works:

TextBox txt1 = new TextBox();
this.Controls.Add(txt1);

this.Controls.Add(createLnkButton("lbt2","lnkBtn2","cmdName2"));


public LinkButton createLnkButton(string id,string text, string cmdName)
{
LinkButton lbt = new LinkButton();
lbt.ID = id;
lbt.Text = text;
lbt.CommandName = cmdName;
lbt.Command += new CommandEventHandler(Handle_Linkbuttons);

return lbt;
}
private void Handle_Linkbuttons(object sender, CommandEventArgs e)
{

LinkButton lb = (LinkButton)sender;
txt1.Text = lb.Text + "::" +e.CommandName.ToString();

}

--------- this doesn't work: -------------------------------------

clsControls.cs_______________

public LinkButton createLnkButton(string id,string text, string cmdName)
{
LinkButton lbt = new LinkButton();
lbt.ID = id;
lbt.Text = text;
lbt.CommandName = cmdName;
lbt.Command += new CommandEventHandler(Handle_Linkbuttons);
return lbt;
}
private void Handle_Linkbuttons(object sender, CommandEventArgs e)
{
controlGrid cg = new controlGrid();
string ee = e.CommandName.ToString();
LinkButton lb = (LinkButton)sender;

txt1 = new TextBox();
txt1.Text = lb.Text; //i must pass the textbox control but i don't know
how
}

webform1_________________

clsControls c = new clsControls();
TextBox txt1 = new TextBox();
this.Controls.Add(txt1);

this.Controls.Add(c.createLnkButton("lbt2","lnkBtn2","cmdName2"));
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top