Search
Monday, September 06, 2010 ..:: Home ::.. Register  Login
 .NET Links Minimize

 Print   
 My Links Minimize

 Print   
 Recent Blog Entries Minimize
Dec 20

Written by: Wil Dobson
12/20/2007 12:29 PM

 

In the event that you need to setup click events for your dynamically created buttons, I would suggest you use button Commands and CommandArgs to indicate what to do and what to do it to.

In this example, I placed a PlaceHolder control into the form where I will want to dynamically place buttons.

// add a dynamic button with command args
        Button mybtn = new Button();
        mybtn.ID = "btnDynamicButton";
        mybtn.Text = "Edit";
        mybtn.CommandName = "Edit";
        mybtn.CommandArgument = "Comments";
        mybtn.Command += new CommandEventHandler(mybtn_Click);
        PlaceHolder1.Controls.Add(mybtn);

Now here is the event handler (will handle all dynamic buttons created with the above code as indicated by the mybtn.Command += ...)

protected void mybtn_Click(object sender, EventArgs e)
    {
        // figure out which action is being requested
        if (((Button)sender).CommandName == "Edit")
        {
            // we are editing
            // figure out what area is being worked on
            string AreaToEdit = ((Button)sender).CommandArgument;
            
            // now we know that we are editing the comments content       
            // put here whatever you want to do to open an editor

            
            // just for testing
            Response.Write("Mode: " + ((Button)sender).CommandName + " - Action: " + AreaToEdit);
        }
    }

Copyright ©2007 Wil Dobson

Tags:

  
 PS: Minimize

 Print   
 Sponsors Minimize

Get your own Komets drinking Stein!

Get your KOMETS gear!
Proceeds go for player awards @ the end of each season.

  Quality Geek Gear from GeeksWithGuns.com

We use DiscountASP!! Click to join up!


 Print   
 Facebook Minimize

Wil Dobson's Facebook profile


 Print   
 Blogs Minimize

 Print   
 Manage Blog Minimize
You must be logged in and have permission to create or edit a blog.

 Print   
 Blog Archives Minimize

 Print   
Copyright 2008 by Wil Dobson   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2010 by DotNetNuke Corporation