Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > linkbuttons dinamically

Reply
Thread Tools

linkbuttons dinamically

 
 
oterox
Guest
Posts: n/a
 
      06-16-2004
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","lnkBtn 2","cmdName2"));


----------------------------------------------------------------------
I just want a to encapsulate the code in the first webform.

Thank you all.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dinamically linkbuttons handler oterox ASP .Net Building Controls 3 06-18-2004 12:55 AM
Linkbuttons not working Stefan Landgraf ASP .Net 0 12-11-2003 01:18 PM
LoadPostData and LinkButtons Lucas Tam ASP .Net 0 08-18-2003 12:57 PM
Re: LinkButtons and MouseOver Vidar Petursson ASP .Net 1 07-09-2003 07:10 AM
Re: Dynamic Table with Dynamic LinkButtons Rick Glos ASP .Net 0 07-08-2003 01:09 PM



Advertisments