Thomas’ Developer Blog

November 12, 2008

Adding multiple AsyncPostBackTriggers dynamically

This one took be a bit of time to figure out, and really can be extremely useful in some cases. This is the situation, you want to set an unknown amount of controls as a triggers to your updatepanel. The problem is you typically have to do this the following way…

Dim mytrigger as new AsyncPostBackTrigger
Mytrigger.ContorlID = “tab1”

Well this works if you have a set amount of triggers. You just do this each time for each trigger and it works out really well. But what if you don’t know how many controls there are. An example of when? Custom server controls, which I have been learning vigorously these last few months.

In this case we have a property which holds several button inputs, or tabs in my case. Well the problem is the developer can add multiple instances of these tab controls, so exactly how do we link them all to the updatepanel?

The answer is in the UpdatePanelTriggerCollection! This wonderful class is used to hold all the triggers within the updatepanel. So to do this we first create the updatepanel followed by the updatepaneltriggercollection.

Dim upnlContent as new updatepanel
upnlContent.UpdateMode = UpdatePanelUpdateMode.Conditional

Dim triggerCollectionContent as new updatepaneltriggercollection(upnlContent)

If you notice you must declare an owner to the triggercollection. In this case being upnlContent.

After you setup the triggerCollect you have to create your triggers with the following code:

triggerCollectionContent.Insert(0, New AsyncPostBackTrigger)
CType(triggerCollectionContent.Item(0), AsyncPostBackTrigger).ControlID = "tab1"

The first line creates a new entry into the collection as a new trigger. The second line sets the controlID for the trigger. If you notice we didn’t have to assign it a variable name! Meaning it’s an array of triggers. So once you have finished inserting all of your triggers using a for loop you then go ahead and go back through that collection and add them to the updatepanel one by one as follows:

upnlContent.triggers.add(triggerCollectionContent.Item(0))

You use the same loop to add them to the updatepanel. Hope that helps you all out!

NOTE: When using this method with a for loop using control.controls.item(i), make sure to use an if statement to check the control type using control.controls.item(i).gettype is gettype(controltype)!!! And make sure to use i instead of 0 if you’re looping.

Advertisements

42 Comments »

  1. I am getting the following error, indicating that Item does not belong to UpdatePanelTriggerCollection. I have included the namespaces System.Web.UI and System.Collections.ObjectModel, but it still doesn’t work.

    CS1061: ‘System.Web.UI.UpdatePanelTriggerCollection’ does not contain a definition for ‘item’ and no extension method ‘item’ accepting a first argument of type ‘System.Web.UI.UpdatePanelTriggerCollection’ could be found (are you missing a using directive or an assembly reference?)

    Comment by Scott — June 25, 2009 @ 3:20 pm

  2. I’m amazed, I have to admit. Rarely do I come across a blog that’s equally educative and amusing, and
    let me tell you, you have hit the nail on the head.
    The problem is something that not enough folks are speaking
    intelligently about. I’m very happy that I found this
    in my search for something regarding this.

    Comment by how to configure best arris tg862g \/ct arris tg862g\/ct — August 6, 2014 @ 1:16 am

  3. Hey! I could have sworn I’ve been to this site before but after
    checking through some of the post I realized it’s new to me.
    Nonetheless, I’m definitely delighted I found it and I’ll be bookmarking and checking
    back frequently!

    Comment by how to configure best comcast best cable modem for cox — August 13, 2014 @ 4:38 am

  4. It’s a shame you don’t have a donate button! I’d certainly donate
    to this brilliant blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to new updates and will share this blog with my Facebook group.
    Chat soon!

    Comment by how to configure best best dsl cable modem for xbox — August 13, 2014 @ 3:37 pm

  5. May I simply just say what a comfort to uncover someone who truly understands what they are talking about over the internet.
    You certainly realize how to bring an issue to light and make it important.

    More and more people have to check this out and understand
    this side of your story. I was surprised you’re not more popular because
    you certainly have the gift.

    Comment by how to configure best best wireless cable modem for comcast — August 16, 2014 @ 9:06 am

  6. Woah! I’m really loving the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s difficult to
    get that “perfect balance” between usability and visual appearance.
    I must say you’ve done a excellent job with this.
    Additionally, the blog loads very quick for me on Chrome.
    Outstanding Blog!

    Comment by how to configure best best wireless best wireless cable modem — August 31, 2014 @ 7:21 am

  7. Heya i’m for the first time here. I found this board and I
    find It truly useful & it helped me out much.
    I hope to give something back and help others like you helped me.

    Comment by how to configure best cable which is the best modem for — August 31, 2014 @ 3:54 pm

  8. I have to thank you for the efforts you have put in writing this website.
    I am hoping to view the same high-grade blog posts by you later on as well.

    In truth, your creative writing abilities has motivated me to get my own, personal website now ;)

    Comment by how to configure best comcast best att dsl modem for xbox — September 2, 2014 @ 8:36 am

  9. I drop a leave a response whenever I appreciate a post on a website
    or I have something to add to the discussion. Usually it is triggered by the passion communicated in the post
    I browsed. And after this post Adding multiple AsyncPostBackTriggers dynamically | Thomas’ Developer Blog.

    I was actually moved enough to drop a thought ;-) I actually do have 2 questions for you if you do not mind.
    Could it be just me or do some of these responses appear
    as if they are written by brain dead folks?

    :-P And, if you are posting on additional places, I would like to keep up with you.
    Would you list the complete urls of your community pages like your linkedin profile, Facebook page or twitter feed?

    Comment by how to configure best arris best docsis 3 cable modem — September 2, 2014 @ 10:01 am

  10. Hey just wanted to give you a brief heads up and let you know a few of the
    pictures aren’t loading properly. I’m not sure why but I think its
    a linking issue. I’ve tried it in two different web
    browsers and both show the same results.

    Comment by how to configure best cable best do you need a modem for — September 4, 2014 @ 5:03 pm

  11. Hi there! I could have sworn I’ve been to this web site before but
    after looking at a few of the posts I realized it’s new to
    me. Anyways, I’m certainly happy I stumbled upon it and I’ll be book-marking it
    and checking back often!

    Comment by how to configure best arris tg862g \/ct arris tg862g\/ct — September 5, 2014 @ 8:50 pm

  12. I like what you guys are usually up too. This type of clever work and coverage!

    Keep up the good works guys I’ve added you guys to my blogroll.

    Comment by how to configure adsl adsl best modem for bsnl broadband — September 7, 2014 @ 1:02 am

  13. Thanks for your marvelous posting! I quite enjoyed reading it,
    you will be a great author. I will make sure to bookmark your blog
    and will often come back in the foreseeable future. I want to encourage you continue your great writing, have a nice afternoon!

    Comment by how to configure best best dsl best comcast modem for — September 8, 2014 @ 9:07 am

  14. Good day! This is my first comment here so I just wanted to give a quick shout out and
    tell you I genuinely enjoy reading your blog posts.

    Can you suggest any other blogs/websites/forums that cover the same subjects?
    Thanks!

    Comment by how to configure best best comcast do you need a modem for — September 11, 2014 @ 4:15 am

  15. I am really loving the theme/design of your weblog.
    Do you ever run into any web browser compatibility issues?
    A couple of my blog visitors have complained about my
    website not operating correctly in Explorer but looks great in Firefox.

    Do you have any advice to help fix this issue?

    Comment by how to configure arris buy cable modem for comcast — September 12, 2014 @ 1:38 pm

  16. What’s up to every , since I am genuinely eager of reading this webpage’s post to be updated daily.
    It contains pleasant material.

    Comment by how to configure best arris best docsis 3 cable modem — September 13, 2014 @ 9:05 pm

  17. Hey there I am so glad I found your website, I really found
    you by mistake, while I was browsing on Askjeeve for something else,
    Nonetheless I am here now and would just like to say kudos for a incredible post and a all round entertaining
    blog (I also love the theme/design), I don’t have time to look over it all at the
    minute but I have saved it and also included your RSS feeds, so when I have time I will
    be back to read a lot more, Please do keep up the awesome job.

    Comment by how to configure best buy best wireless modem for comcast — September 18, 2014 @ 5:53 am

  18. Hi, everything is going sound here and ofcourse every
    one is sharing facts, that’s genuinely fine, keep up writing.

    Comment by how to configure best best cable the best modem for xbox — September 18, 2014 @ 2:03 pm

  19. I’ve been surfing online greater than 3 hours as of late,
    but I by no means discovered any interesting article like yours.
    It’s beautiful worth sufficient for me. In my opinion, if all webmasters and bloggers
    made good content material as you did, the web will
    probably be much more helpful than ever before.

    Comment by how to configure best comcast best cable modem for wow — September 19, 2014 @ 11:38 am

  20. Hey! I know this is kind of off topic but I was wondering which blog platform are you using for this website?
    I’m getting sick and tired of WordPress because
    I’ve had issues with hackers and I’m looking at alternatives for another platform.
    I would be fantastic if you could point me in the direction of a good platform.

    Comment by how to configure best comcast do you do u need a modem — September 19, 2014 @ 5:01 pm

  21. Good day I am so glad I found your website, I really found you by
    error, while I was researching on Google for something else, Nonetheless I am here now and
    would just like to say many thanks for a remarkable
    post and a all round thrilling blog (I also love the theme/design), I don’t have time to read it
    all at the minute but I have book-marked it and also
    added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the
    excellent jo.

    Comment by how to configure best cable best cable modem for mac — September 20, 2014 @ 8:32 am

  22. Thankfulness to my father who told me regarding this weblog, this webpage is in fact amazing.

    Comment by how to configure best best best modem for bsnl broadband — September 20, 2014 @ 10:28 am

  23. We stumbled over here by a different web address and thought I should check things out.
    I like what I see so now i am following you. Look forward to going
    over your web page again.

    Comment by how to configure best cable dsl best modem for xbox live — September 21, 2014 @ 2:26 pm

  24. I’ve learn some just right stuff here. Certainly price bookmarking for revisiting.
    I surprise how much attempt you place to create this kind of wonderful informative web site.

    Comment by how to configure best best wireless best wireless cable modem — September 21, 2014 @ 3:37 pm

  25. What’s Going down i’m new to this, I stumbled upon this I’ve found It
    absolutely helpful and it has aided me out loads.
    I hope to give a contribution & aid other customers like its helped me.
    Good job.

    Comment by how to configure best best dsl how to configure modem — September 23, 2014 @ 12:20 pm

  26. Oh my goodness! Awesome article dude! Thanks, However I am having troubles with your RSS.
    I don’t understand why I am unable to join it. Is there anybody else having identical RSS
    problems? Anyone that knows the solution can you kindly respond?

    Thanks!!

    Comment by worst date movies buzzfeed — September 25, 2014 @ 5:35 am

  27. You really make it seem really easy together with your presentation but I find this matter to be really something which I think I might by no means
    understand. It kind of feels too complicated and very large for me.
    I’m taking a look forward in your subsequent put up, I’ll
    attempt to get the hang of it!

    Comment by how to configure best best cable best modem for xbox live — September 25, 2014 @ 9:51 am

  28. First of all I want to say awesome blog! I had a quick question which I’d like to ask if you don’t
    mind. I was interested to find out how you center yourself and clear your head prior
    to writing. I’ve had difficulty clearing my thoughts in getting my
    ideas out there. I truly do take pleasure in writing however it just seems like the
    first 10 to 15 minutes are usually wasted simply just trying to figure out how to begin. Any recommendations or tips?
    Thanks!

    Comment by how to configure best best buy modem for comcast — September 25, 2014 @ 9:58 am

  29. Fastidious response in return of this difficulty with genuine arguments and telling all on the topic of that.

    Comment by how to configure bsnl wireless adsl modem — September 25, 2014 @ 10:20 am

  30. Now I am going to do my breakfast, once having my breakfast coming
    over again to read more news.

    Comment by how to configure best best comcast cable modem for xbox — September 25, 2014 @ 7:49 pm

  31. Hiya! I know this is kinda off topic nevertheless I’d figured I’d
    ask. Would you be interested in trading links
    or maybe guest authoring a blog article or vice-versa?
    My website addresses a lot of the same subjects as yours and I feel we could greatly benefit from each other.
    If you happen to be interested feel free to send me an email.
    I look forward to hearing from you! Fantastic blog
    by the way!

    Comment by how to configure best best docsis 3 best cable modem for comcast — September 27, 2014 @ 5:40 am

  32. Hey! Do you know if they make any plugins to help with Search Engine Optimization? I’m
    trying to get my blog to rank for some targeted keywords but I’m not seeing very
    good results. If you know of any please share. Thank you!

    Comment by how to install billion modem — September 27, 2014 @ 12:20 pm

  33. This is really interesting, You are a very skilled blogger.
    I have joined your feed and look forward to seeking more of your wonderful post.
    Also, I’ve shared your website in my social networks!

    Comment by how to configure best best best wireless modem for comcast — September 27, 2014 @ 2:43 pm

  34. Hi! I could have sworn I’ve visited this site before but after
    browsing through many of the articles I realized it’s new to me.
    Nonetheless, I’m certainly delighted I discovered
    it and I’ll be book-marking it and checking back frequently!

    Comment by how to configure best comcast best cable modem for suddenlink — September 28, 2014 @ 11:15 pm

  35. Simply want to say your article is as astounding. The clearness to your
    put up is simply excellent and that i can think you’re an expert
    on this subject. Well with your permission let me to seize your feed to stay updated with imminent post.

    Thank you one million and please continue the enjoyable work.

    Comment by how to configure best arris best wireless cable modem — September 28, 2014 @ 11:29 pm

  36. Spot on with this write-up, I honestly believe that this site needs
    a great deal more attention. I’ll probably be returning to see more, thanks for the advice!

    Comment by how to configure bsnl wireless adsl modem — September 30, 2014 @ 6:34 pm

  37. Your style is very unique in comparison to other folks I’ve read stuff
    from. Thanks for posting when you’ve got the opportunity, Guess I will just bookmark this page.

    Comment by how to configure best comcast best best att dsl modem for — September 30, 2014 @ 8:53 pm

  38. Attractive component to content. I just stumbled upon your website and in accession capital to say that I acquire in fact enjoyed account your
    blog posts. Any way I’ll be subscribing on your augment or even I fulfillment you get entry to constantly quickly.

    Comment by how to configure best best wireless wireless cable modem for — September 30, 2014 @ 10:29 pm

  39. Wow, amazing blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your website is magnificent, as well as the content!

    Comment by how to configure best comcast how to configure modem linux — September 30, 2014 @ 11:15 pm

  40. What’s up, just wanted to say, I liked this blog post.

    It was practical. Keep on posting!

    Comment by first direct bank card — October 3, 2014 @ 1:55 am

  41. Definitely believe that which you stated. Your favorite reason appeared to be at the net the easiest factor
    to take note of. I say to you, I certainly get annoyed
    at the same time as other folks think about issues that they just do not
    know about. You managed to hit the nail upon the highest and also
    outlined out the whole thing without having side
    effect , other folks can take a signal. Will probably be again to get more.

    Thanks

    Comment by Il mondo dell’archeologia — October 5, 2014 @ 2:48 am

  42. Hey there, I think your website might be having browser compatibility issues.

    When I look at your blog in Chrome, it looks fine but when opening in Internet Explorer, it
    has some overlapping. I just wanted to give you a quick heads
    up! Other then that, terrific blog!

    Comment by Il mondo dell’archeologia — October 5, 2014 @ 2:59 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: