Results 1 to 8 of 8

Thread: [2005] Page Control Events

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Resolved [2005] Page Control Events

    I have a class that inherits from Page.
    In the OnLoad method i'm looping through all controls on the page (recursively) before i call base.OnLoad. If the control is a ImageButton (in this example) then i want to add an event handler for its clicked event.
    Code:
    if (Ctrl is ImageButton)
    {
        ((ImageButton)Ctrl).Click += new ImageClickEventHandler(ImageButtonClick);
    }
    This code definatly gets called for each control that is an ImageButton.

    My ImageButtonClick event is as below:
    Code:
    public void ImageButtonClick(object sender, ImageClickEventArgs e)
    {
        new GUIWebEvent(sender.ToString(), "Click").Raise();
    }
    This NEVER gets called. I've double checked this by inserting int x = 0;x = 1 / x; within the method, so i know it never gets called.

    Any ideas why? My only thought is that i'm doing it in the OnLoad method, but i'm pretty stuck as to how i can get this to work.
    Last edited by SLH; Nov 5th, 2008 at 08:25 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] Page Control Events

    According to the MSDN the ASP.Net page lifecycle states that OnInit is called before OnLoad. OnInit is where all controls are created / initialized and the ViewState / ControlState is loaded so I see no issues with you using the OnLoad event.

    Looking at the ImageButton Members, perhaps you need to specify it as OnClick rather than Click?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [2005] Page Control Events

    I don't think it'd be OnClick, since that's the method that's called when the event is fired. I want to add my handler method to the actual Click event its self (just like you'd do on a windows.forms application).
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] Page Control Events

    Quote Originally Posted by SLH
    I don't think it'd be OnClick, since that's the method that's called when the event is fired. I want to add my handler method to the actual Click event its self (just like you'd do on a windows.forms application).
    I understand what you're trying to do and I don't really use many ASP controls but according to the OnClick property in the MSDN, the example specifically assigned the event method to call to the OnClick property so it seems odd that you're using Click instead of OnClick.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [2005] Page Control Events

    That's a protected method and so i can't access it in the code-behind (without overriding ImageButton).
    I think the example works because it's doing it on the actual ASPX page.

    Looking at the MSDN page for the click event it has the declarations for c#, vb.net ... and asp.net, where for asp.net it has the line OnClick=...., so i guess the OnClick reference in the ASPX file is the same.

    There must be something daft i'm doing though, since all the examples i've seen appear to be the same as mine (control.Click += .....)
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: [2005] Page Control Events

    This simple base class works fine for me, which is really nothing different than what you seem to be doing. So using OnLoad is fine...

    Code:
    public class PageBase : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            System.Diagnostics.Debug.Print("OnLoad");
    
            foreach (Control ctrl in Page.Form.Controls)
            {
                if (ctrl is ImageButton)
                {
                    ((ImageButton)ctrl).Click += new ImageClickEventHandler(ImageButtonClick);
                }
            }
    
            base.OnLoad(e);
        }
    
        protected void ImageButtonClick(object sender, ImageClickEventArgs e)
        {
            System.Diagnostics.Debug.Print("ImageButtonClick");
        }
    }

  7. #7

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [2005] Page Control Events

    I think my issue is that the imagebutton's are in an UpdatePanel (an AJAX web control that automatically performs async postbacks for child controls).

    Not sure how to resolve this issue though.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  8. #8

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [2005] Page Control Events

    I've managed get most controls to work by having the class replace (and inherit from) ScriptManager, rather than Page.

    One control that doesn't work still is the Menu control. Not sure quite why though but i can live with it.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width