Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Create and add event for linkbutton

Create and add event for linkbutton

Scheduled Pinned Locked Moved ASP.NET
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ctlqt12
    wrote on last edited by
    #1

    Hi all, I have a form with a button and a textbox. When i click button, linkbutton will be create on form. When i click linkbutton, "Hello" will be filled into textbox.

    protected void Button1_Click(object sender, EventArgs e)
    {
       LinkButton lbtn = new LinkButton();
       lbtn.ID = "MyLinkButton";
       lbtn.Text = "Welcome";
       lbtn.Command += new CommandEventHandler(lbtn_Command);
       form.Controls.Add(lbtn);
    }
    
    
    protected void lbtn_Command(object sender, CommandEventArgs e)
    {
       txt.Text = "Hello";
    }
    

    But when i click LinkButton, Command event is not raised. What can i do to raise Command event of LinkButton?

    I 1 Reply Last reply
    0
    • C ctlqt12

      Hi all, I have a form with a button and a textbox. When i click button, linkbutton will be create on form. When i click linkbutton, "Hello" will be filled into textbox.

      protected void Button1_Click(object sender, EventArgs e)
      {
         LinkButton lbtn = new LinkButton();
         lbtn.ID = "MyLinkButton";
         lbtn.Text = "Welcome";
         lbtn.Command += new CommandEventHandler(lbtn_Command);
         form.Controls.Add(lbtn);
      }
      
      
      protected void lbtn_Command(object sender, CommandEventArgs e)
      {
         txt.Text = "Hello";
      }
      

      But when i click LinkButton, Command event is not raised. What can i do to raise Command event of LinkButton?

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Problem is when u click on Button then LinkButton will be created and added in the form.But when u click on the Linkbutton at that time u can not create linkbutton againg.You have to create every postback. try to create it on Page_Load event try this code. protected void Page_Load(object sender, EventArgs e) { CreateBtn(); } protected void Button1_Click(object sender, EventArgs e) { CreateBtn(); } public void CreateBtn() { LinkButton lnk= new LinkButton(); lnk.ID = "MyLinkButton"; lnk.Text = "Welcome"; lnk.Click += new EventHandler(lnk_Click); form.Controls.Add(lnk); } public void lnk_Click(object sender, EventArgs e) { txt.Text = "Hello"; } Best Regard Pathan

      ---------------------------------------------------

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups