Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET - Accessing All ImageButtons on a Page and Putting Two Images on an ImageButton
    primarykey
    data
    text
    <p>I actually have two questions: </p> <p>(1) Is it possible to put <em>another</em> image on top of an ImageButton that already has an ImageUrl set (without changing the ImageUrl - literally just add the second image 'on top')? Even by using CSS?</p> <p>(2) I have a dynamically set number of ImageButtons contained within a ListView. When a user clicks on an ImageButton, I change the <code>.CssClass</code> property of the one clicked in order to 'highlight' it. My question is this: whenever an ImageButton is click, I need to not only highlight it, but make sure I <em>unhighlight</em> all the others. However, I'm having trouble getting the others. I get the clicked ImageButton using</p> <pre><code>((ImageButton)sender).CssClass = "SelectedImageButton"; </code></pre> <p>in the event handler. However, how do I get all the others so I can set their style 'back' to the unhighlighted style?</p> <p>Thanks in advance for any help!</p> <p><strong>UPDATE: ANSWERED!</strong> I've solved the issue mentioned in (2) using the following algorithm. Note, I've marked @OFConsulting's answer below as the correct answer because without his algorithm, I would have never gotten the following algorithm (which came from tweaking his algorithm slightly). Thanks @OFConsulting!</p> <pre><code>// Cast the sender to an ImageButton to have the clicked ImageButton ImageButton clickedImageButton = sender as ImageButton; // The ListView has ListViewDataItems and the ImageButtons are in // THOSE children controls, thus match on the ImageButtons' Parents' IDs Control parentControl = clickedImageButton.Parent; List&lt;ListViewDataItem&gt; allOtherImageButtons = MyListView.Controls.OfType&lt;ListViewDataItem().AsQueryable().Where(i =&gt; i.ID != clickedImageButton.Parent.ID).ToList(); // Highlight clickedImageButton.CssClass = "HighlightedStyle"; // Unhighlight foreach (ListViewDataItem button in allOtherImageButtons) { // The ImageButton is always the 2nd child control of the ListViewDataItem ImageButton childImageButton = (ImageButton)button.Controls[1]; childImageButton.CssClass = "NoHighlightedStyle"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload