Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 107,710 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,099 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Button event handler

 
Reply to this topicStart new topic

Button event handler, C#.NET problem

reCoded
post 1 Jul, 2008 - 01:02 PM
Post #1


D.I.C Head

**
Joined: 25 Feb, 2008
Posts: 121

Hey all,

I have this is a different method

CODE
                    Button btnEdit = new Button();
                   btnEdit.ID = "Edit_" + begin.Ticks.ToString();
                   btnEdit.CssClass = "MainButtons";
                   btnEdit.Text = "Edit Cards";
                   btnEdit.Click += new EventHandler(EditCards);



This is the code I want to be called once this line is executed:
btnEdit.Click += new EventHandler(EditCards);

CODE


        public void EditCards(object source, EventArgs e)

        {
                    /////////////code here//////
        }


Anyone know why the method EditCards is not executed? I am stumped.

This is C#.NET and framework 3.0

Thanks,
reCoded.
User is offlineProfile CardPM

Go to the top of the page


Redian
post 1 Jul, 2008 - 04:24 PM
Post #2


New D.I.C Head

*
Joined: 28 Dec, 2007
Posts: 21

I'm not quite sure I followed, but there is no place where you actualy execute it. You should try then typing button.Click(); to execute the method. But then again, I'm not too sure...
User is offlineProfile CardPM

Go to the top of the page

jayman9
post 1 Jul, 2008 - 07:21 PM
Post #3


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,300



Thanked 21 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Topic renamed to be more descriptive.
User is offlineProfile CardPM

Go to the top of the page

nbarten
post 1 Jul, 2008 - 11:22 PM
Post #4


D.I.C Head

**
Joined: 30 Apr, 2007
Posts: 112



Thanked 1 times
My Contributions


your eventhandler seems ok... do you actually see the button on your form? When you click it, it won't do what it should do? (in the event handler)
User is offlineProfile CardPM

Go to the top of the page

zakary
post 2 Jul, 2008 - 05:04 AM
Post #5


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 370



Thanked 4 times

Dream Kudos: 175
My Contributions


You have a method that creates a button, and that button has no Location nor do I see where it is being add to the form Control.

csharp

Button btnEdit = new Button();
// Point is the x,y location on form
btnEdit.Location = new System.Drawing.Point(84, 169);
btnEdit.ID = "Edit_" + begin.Ticks.ToString();
btnEdit.CssClass = "MainButtons";
btnEdit.Text = "Edit Cards";
btnEdit.Click += new EventHandler(EditCards);
this.Control.Add(this.btnEdit);
User is offlineProfile CardPM

Go to the top of the page

reCoded
post 2 Jul, 2008 - 06:18 AM
Post #6


D.I.C Head

**
Joined: 25 Feb, 2008
Posts: 121

Yeah I can see the buttons...More than one...When I create one button it works but not when I create multiple buttons..I will give the code that zakary posted and will let you guys know if it works.

Thanks for all the replies,
reCoded
User is offlineProfile CardPM

Go to the top of the page

eclipsed4utoo
post 2 Jul, 2008 - 06:29 AM
Post #7


D.I.C Head

**
Joined: 21 Mar, 2008
Posts: 97



Thanked 5 times
My Contributions


QUOTE(reCoded @ 2 Jul, 2008 - 06:18 AM) *

Yeah I can see the buttons...More than one...When I create one button it works but not when I create multiple buttons..I will give the code that zakary posted and will let you guys know if it works.

Thanks for all the replies,
reCoded


all controls that are not given a specific location will default to (0,0). So even though you add multiple buttons, they are all sitting on top of each other.
User is offlineProfile CardPM

Go to the top of the page

reCoded
post 2 Jul, 2008 - 06:58 AM
Post #8


D.I.C Head

**
Joined: 25 Feb, 2008
Posts: 121

Yeah I took care of that problem thanks...I have found that when adding the controls to the button there is a post back. Once the post back accurs I need to set the controls back to the buttons. Any idea how I can accomplish this?

thanks,
reCoded
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/30/08 03:23AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month