Holaaa.
He creado un metodo que crea un linkbutton dinamicamente y al hacer click en
el escribe un texto
en un textBox.Funciona bien si el codigo esta todo en el webform1.He
intentado sacar ese metodo a
una clase, clsControls, y ya no funciona porque no se como acceder al
textbox desde otra
clase.Imagino que pasandole el textbox como parametro:
Esto funciona:
webform1 --
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();
}
Esto no funciona -
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;
//Esto no se como seria:
txt1 = new TextBox();
txt1.Text = lb.Text;
}
webform1_________________
clsControls c = new clsControls();
TextBox txt1 = new TextBox();
this.Controls.Add(txt1);
this.Controls.Add(c.createLnkButton("lbt2","lnkBtn2","cmdName2"));
-
Lo que quiero es encapsular ese metodo y sacarlo del webform.
Gracias a todos.
un saludo.
Leer las respuestas