Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Anonymous Methods and asp.net

Back to Forum: Tech Off
  • User profile image
    wacko

    This must not be my week Sad I have been working on some stuff that I would like to use Anonymous Methods for but it seems that even if I just take a lonley asp button and try to tack on a Anonymous Methods in the page load event, nothing seems to happen. Is there some level of restriction on Anonymous Methods ?

    EDIT: I got it working Sad darn it wasted a good thread.

    but I did find something interesting that I think is worth noting and maybe its a bug but who knows... Let me post the following code :

    protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Click += delegate(object MyObject, EventArgs MyEvents){Button1.Text = "Test";};
        }
    


    the code above does not work, it will not change the text of the button; with that being said the following code will change the button
    
    protected void Page_Load(object sender, EventArgs e)
    
        {
           this.Button1.Click += delegate(object
    MyObject, EventArgs MyEvents){this.Button1.Text = "Test";};
    
        }
    
    


    noting that I had to add this in front of the button, which is wierd becuse this works

    protected void Button1_Click(object sender, EventArgs e)
        {
            Button1.Text = "Test";
        }
    


    Is this just something with Anonymous Methods and asp.net ?

  • User profile image
    footballism

    protected void Page_Load(object sender, EventArgs e)
    {
          this.Button1.Click += delegate { Button1.Text = "Test";};
     }

    This works here for me:p

    Sheva

  • User profile image
    wacko

    hmm i wonder why it does not work for me ?

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.