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:
--- 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"));
the method is in the webform but if i try to put the method in a different
class it doesn't work:
--- 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"));