linkbuttons dinamically

Discussion in 'ASP .Net Web Controls' started by oterox, Jun 16, 2004.

  1. oterox

    oterox Guest

    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"));


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

    Thank you all.
     
    oterox, Jun 16, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vidar Petursson

    Re: LinkButtons and MouseOver

    Vidar Petursson, Jul 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,280
    sramruttun
    Jul 9, 2003
  2. Rick Glos
    Replies:
    0
    Views:
    650
    Rick Glos
    Jul 8, 2003
  3. Lucas Tam

    LoadPostData and LinkButtons

    Lucas Tam, Aug 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    330
    Lucas Tam
    Aug 18, 2003
  4. Stefan Landgraf

    Linkbuttons not working

    Stefan Landgraf, Dec 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    343
    Stefan Landgraf
    Dec 11, 2003
  5. oterox

    dinamically linkbuttons handler

    oterox, Jun 16, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    163
    Victor Garcia Aprea [MVP]
    Jun 18, 2004
Loading...

Share This Page