Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding click events to user control
    text
    copied!<p>I have a user control in an asp.net web application. The control outputs an html list that is customized based on the currently logged in user. The list items are generated from a database look up and the user control is formatted to appear as a drop down list in the page.</p> <p>The control itself is simple and looks like this:</p> <pre><code>&lt;%@ Control Language="VB" AutoEventWireup="false" CodeFile="item-lector.ascx.vb" Inherits="includes_usercontrols_item_selector" %&gt; &lt;!--Item Selector--&gt; &lt;div id="item-selector"&gt; &lt;%=Me.Output%&gt; &lt;/div&gt; </code></pre> <p>The code behind file dynamically fills the control's "output" property so the final markup appears as follows:</p> <pre><code>&lt;div id="item-selector"&gt; &lt;h1&gt;Item 1 - Item 1&lt;/h1&gt; &lt;a href="#" class="changeItem itemArrow"&gt;Change item&lt;/a&gt; &lt;ul id="changeItemMenu" class="dropDownMenu"&gt; &lt;li&gt;&lt;a href="#"&gt;Item 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 5&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 6&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 7&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 8&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 9&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Item 10&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>The ID and class properties are all necessary for formatting and other scripting. The control is meant to be used as a selector and the rest of the page should react to which item the user selects.</p> <p>What I am trying to do is add click events to the list items. When the user clicks on one of the items in the list, I want to capture which item the user selects in the list (does this require a postback?) and <strong>do something with it in the code behind</strong> (&lt; this is key). </p> <p>I am more of a middle tier and db tier developer and UI development is not my strength so please consider me a newbie in that regard. I am not sure how to proceed or what to inject into the output string to enable this. Any and all help would be appreciated!</p>
 

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