+ Reply to Thread
Results 1 to 7 of 7

Thread: Assigning Event Handler to Repeater in Custom Control

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Assigning Event Handler to Repeater in Custom Control

    I have written a custom control to render a check box list to the page. The default .NET one didn't render to my page correctly because I needed to Enable / Disable the checkboxes depending on user permissions.

    What I now need to do is add an OnItemDataBound event to the repeater inside the control by assigning it a sub from my page.

    Basically I want to be able to have in my page:-
    Code:
    myCustomControl.OnItemDataBound = ASubRoutineInMyPage
    .
    .
    protected void ASubRoutineInMyPage(object s, RepeaterItemEventArgs e)
    {
    .
    .
    .
    }
    
    I'm not entirely sure what I should have in my custom control to expose this method, allow me to apply my own subroutine to it and then execute this OnItemDataBound event when my control loads.

    Any ideas or examples I could try?

    I want to reuse the control in a number of pages and so need to be able to call a different routine depending on the page, or no event at all.

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Still not quite getting it. This is what I have
    Code:
        public delegate void RepeaterDelegate(object s, RepeaterItemEventArgs e);
        protected event RepeaterDelegate _ItemDataBound;
        public event RepeaterDelegate ItemDataBound
        {
            add
            {
                if (this._ItemDataBound == null) this._ItemDataBound += value;
            }
            remove
            {
                if (this._ItemDataBound != null) this._ItemDataBound -= value;
            }
        }
    
        public virtual void OnItemDataBound()
        {
            RepeaterItemEventArgs evt = new RepeaterItemEventArgs(item);
            if (this._ItemDataBound != null) this._ItemDataBound(this, evt);
        }
    
    But I don't understand where I get the repeater item instance required in my OnItemDataBound void (highlighted in red).

    In the example in the link, the event is added to a dropdownlist. In this I need to add it to a repeater item, I think.

    I tried adding a foreach (repeateritem item in myRep.items) and there were no errors, but none of the checkboxes that should have been checked, were. I will check the logic in my repeater item sub, but it was working fine when it was in the User Control code behind. Maybe I'm missing a value in it somewhere.

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. I just tried changing something in the sub that I want called OnItemDataBound and nothing changed in the page, so I guess it's not calling it or not calling it correctly.

  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    OK. I've sort of given up with this now. I realised that the rendering of the checkboxes was related to one specfic use and so that would have meant changing this as well to reuse the control.

    I'd still like to get this sorted if possible. Basically I want to be able to pass event handlers from my page to my user control and then attach them to a repeater inside the control.

  6. #6
    Barn Newbie Kraevin is on a distinguished road Kraevin's Avatar
    Join Date
    Mar 2010
    Posts
    7
    Rep Power
    2

    Use Composite Control

    To do what you want you need to create a composite control instead of a user control. It would be nice if they offered some nice easy way to add custom events and event handling to user controls but there isnt. Unfortunately there is no really GUI support for a composite control so it can get sticky.

  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Will take a look at composite controls when I get the chance.

    Thanks

+ Reply to Thread

Similar Threads

  1. Custom Calendar Control
    By AOG123 in forum Access Database Samples
    Replies: 6
    Last Post: December 10th, 2008, 05:34 PM
  2. Object Reference Error on Custom Control Postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: September 22nd, 2008, 06:56 PM
  3. reference control from nested repeater
    By Shem in forum .NET Development
    Replies: 18
    Last Post: September 15th, 2008, 11:46 AM
  4. paging enabled in a repeater control
    By peebman2000 in forum .NET Development
    Replies: 6
    Last Post: September 4th, 2008, 12:15 PM
  5. adding an event for my btnDelete in repeater
    By Shem in forum .NET Development
    Replies: 13
    Last Post: July 15th, 2008, 10:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

SEO by vBSEO