controles dinamicos

16/06/2004 - 11:02 por oterox | Informe spam
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.

Preguntas similare

Leer las respuestas

#1 Jose Marcenaro
16/06/2004 - 17:02 | Informe spam
Podrias agregar esta propiedad a tu clase clsControls:

// textbox a modificar en el LinkButton
private TextBox txtParaLinkButton;

Y modificar así el método createLinkButton:

public LinkButton createLnkButton(string id,string text, string cmdName,
TextBox txt)
{
txtParaLinkButton = txt;
... // todo tu codigo actual
}

Entonces en Handle_Linkbuttons dispones de la propiedad
this.txtParaLinkButton que es el control a modificar...

Saludos
Jose Marcenaro

"oterox" escribió en el mensaje
news:
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.


Respuesta Responder a este mensaje
#2 oterox
17/06/2004 - 09:34 | Informe spam
Muchas gracias Jose.
Funciona perfectamente con lo que me has dicho.

"Jose Marcenaro" wrote in message
news:
Podrias agregar esta propiedad a tu clase clsControls:

// textbox a modificar en el LinkButton
private TextBox txtParaLinkButton;

Y modificar así el método createLinkButton:

public LinkButton createLnkButton(string id,string text, string cmdName,
TextBox txt)
{
txtParaLinkButton = txt;
... // todo tu codigo actual
}

Entonces en Handle_Linkbuttons dispones de la propiedad
this.txtParaLinkButton que es el control a modificar...

Saludos
Jose Marcenaro

"oterox" escribió en el mensaje
news:
> 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.
>
>


email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida