Catching Dynamic Button Events


Hi!



Is there any consensus as to the best way to handle dynamic button clicks? The buttons are being created dynamically and conditionally placed, depending on business logic.



Our problem is that on clicking such a button, the postback calls the Page\_Load but not the Button\_OnClick. I notice that if I use a static button on the page, this problem does not occur, but that thwarts our business logic.



What we're trying to achieve is to add an "Edit" button. When clicked, it changes the layout of the page, and no longer shows this "Edit" button. (Instead, "Save", "Discard", etc...).



We're trying to avoid making the buttons static, with visibility controlled by logic, as that would be such a limiting factor. e.g. we may want a dynamic array of buttons where the size of the array is unknown at design time. How would their click events be caught?



Any ideas?!  

Stewart



```
Button EditButton;
 
protected void Page_Load(object sender, EventArgs e) {
  if (!IsPostBack) {
    setupMostOfPage(); // based on business logic
  }
 
  if (!editMode) {
    // creates and places the button in placeholder if not in editMode
    setupEditButton();
  }
}
 
EditButton_OnClick(object sender, EventArgs e) {
  // doesn't go here even when business logic creates button
 
  editMode = !editMode; 
  setupMostOfPage(); // now sets it up based on editMode
}
```
when you create the buton are you setting up the event handler?



```
this.EditButton.Click += new System.EventHandler(this.EditButton_OnClick);
```

Normally this created behind the scenes by visual studio.
for example, you can disable right click on images at your page:

```

$(document).ready(function() {
    $("img").on("contextmenu",function(){
       return false;
    }); 
}); 

``` hi tomica, - - i can suggest that you try the following: -     - remove all of the styles to see whether some specific css is affecting the buttons appearance. -     - upgrade to latest telerik ui version - 2015.2.826 - if the above steps, however, do not help it would be better to provide us with a runnable sample that reproduces the issue, so that we can investigate it further. - - regards, - danail vasilev - telerik - - do you want to have your say when we set our development plans? - do you want to know when a feature you care about is added or when a bug fixed? - explore the - telerik feedback portal - and vote to affect the priority of the items - hey [@jsteb](/u/jsteb), i was struggling with this and i figured what is going on. the problem is with the action button. if you try with a regular button it will work. i think that should be clarified in the tutorial Put the grid inside a panel (rather than scrolling the grid itself) and the following in the head section of the page. This is set for using a MasterPage, but you can remove the "ctl00\_MainContentPlaceHolder\_" prefix for a regular page.  

  

XMLCopy Code

```
<script type="text/javascript" language="javascript">
        window.onload = function () {
                var strCook = document.cookie;

                if (strCook.indexOf("!~") != 0) {
                        var intS = strCook.indexOf("!~");
                        var intE = strCook.indexOf("~!");
                        var strPos = strCook.substring(intS + 2, intE);
                        document.getElementById("ctl00\_MainContentPlaceHolder\_pnlFindings").scrollTop = strPos;
                }

        }
</script>
<script type="text/javascript" language="javascript">
        function SetDivPosition() {
                var intY = document.getElementById("ctl00\_MainContentPlaceHolder\_pnlFindings").scrollTop;
                document.cookie = "yPos=!~" + intY + "~!";
        }
</script>
```
  

  

In the Panel, you'll need:   

 onscroll="SetDivPosition()"  

  

That should do it for you. Works for me, anyway. you should be able to set the element to not be visible on page load, and then on the conditional tab of the element, you should be able to construct a condition where parent group’s thing’s creation date < parent group’s thing’s modified date, this element is visible. and when i say “should be able… You would be better to turn off lazy loading by default and instead specify when you want to load the extra data in the first place. EF is set up to allow Eager loading by using the .Include() function on your query, with lazy loading it can get messy if you start turning it on/off for various functions, you're better to just turn it off and manage what/when you want data loaded if you're feeling a need to turn it off.


See <https://msdn.microsoft.com/en-nz/data/jj574232.aspx> for specific examples and a breakdown of the different ways you can eager/lazy load data. The first example shows how you could pull through posts off a blog, which is similar to what you are wanting to acheive.



```
var topics = context.Topics 
                      .Include(t => t.Posts) 
                      .ToList(); 

``` [image] dueck456:

is there an easy way to detect when new code is flashed to the device so i can reinitialize the retained variables?

below is a link to a post by [@rickkas7](/u/rickkas7) about storing retained data in a struct.

[image] dueck456:

saving a know value to eeprom jumps to mind

there is … hey [@andre601](/u/andre601) ! i think there is a webhook that fires for that:

<https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request>

check out the action key in the payload, it has support for state changes between draft and non-draft states. i just figured out what the problem was. if you enable the “titlebar” in firefox’s “customize…” window (it is a checkbox at the bottom) then the traditional window titlebar appears (with the buttons on the left) and the click and drag thing works. who knew? hello john, - thank you for contacting us. - - here are the answers to your questions: - 1. in order to set the position of the pin button, you need to change the way it is docked in the caption area. here is a sample code snippet which loops though all toolwindows and sets the position of the pin button to left: - - for (int i = 0; i this.raddock1.dockwindows.toolwindows.length; i++) - { -     this.raddock1.dockwindows.toolwindows[i].toolcaptionbuttons = telerik.wincontrols.ui.docking.toolstripcaptionbuttons.autohide; -   -     tooltabstrip strip = (tooltabstrip)this.raddock1.dockwindows.toolwindows[i].tabstrip; -     radtogglebuttonelement pinbutton = (radtogglebuttonelement)strip.captionelement.children[2].children[1]; -     docklayoutpanel.setdock(pinbutton, telerik.wincontrols.layouts.dock.left); - } - - 2. you can open autohide window only on click by handling the autohidewindowdisplaying event and checking what is the reason for which the window is going to be shown. if it is tabitemclicked, then we can allow the operation: - - void raddock1\_autohidewindowdisplaying(object sender, autohidewindowdisplayingeventargs e) - { -     if (e.displayreason == autohidedisplayreason.tabitemclicked) -     { -         return; -     } -     e.cancel = true; - } - - 3. currently, there is an issue with the size of the autohide windows and although it is set by the autohidesize property, the autohide window still can't cover the entire raddock area. it is logged in our public issue tracker, but i cannot provide you with a workaround for the time being. - kind regards, - nikolay - the telerik team - - you’ve been asking for it and now it’s time for us to deliver. radcontrols for winforms q3 2012 release is just around the corner. sign up for a free webinar to see first all the latest enhancements. -