Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing dynamically created elements from inside of a repeater
    primarykey
    data
    text
    <p>I need to create a series of dynamically created buttons inside of a repeater. These buttons names are coming from a database. When a user clicks a button, some hidden text beside the name appears. And disappears when clicked again. The text will have to be either defined in the html or the code behind. </p> <p>Here is some code to demonstrate what I'm thinking. </p> <pre><code> &lt;asp:Repeater ID="Repeater1" DataSourceID="DecisionDetailsDS" runat="server" &gt; &lt;ItemTemplate&gt; &lt;asp:Button ID="DecisionButton" runat="server" OnClick="BTN_ShowText" BorderStyle="None" Text='&lt;%# Eval("Decision_Type_Dsc") %&gt;' /&gt; &lt;asp:Label ID="DecisionLabel" Visible="false" runat="server" /&gt; &lt;p&gt;&lt;/p&gt; &lt;/ItemTemplate&gt; &lt;AlternatingItemTemplate&gt; &lt;asp:Button ID="DecisionButton" runat="server" OnClick="BTN_ShowText" BorderStyle="None" Text='&lt;%# Eval("Decision_Type_Dsc") %&gt;' /&gt; &lt;asp:Label ID="DecisionLabel" Visible="false" runat="server" /&gt; &lt;p&gt;&lt;/p&gt; &lt;/AlternatingItemTemplate&gt; &lt;/asp:Repeater&gt; public void BTN_ShowText(Object sender, EventArgs e) { Label TestLabel = (Label)FindControl("DecisionLabel"); Button TestButton = (Button)FindControl("DecisionButton"); switch(TestButton.Text) { case "Dismissed": TestLabel.Text = "Testing 1 2 3"; break; case "Anything": TestLabel.Text = "Testing 2 3 4"; break; } if (TestLabel.Visible == false) { TestLabel.Visible = true; } else { TestLabel.Visible = false; } } } </code></pre> <p>I know this doesn't work. I get nulls returned. Whereas I need the id of the button and it's corresponding label. Hopefully this gives you an idea of what I'm trying to do. Any suggestions are appreciated especially if you provide my some code to work with. I thought maybe using jquery?</p> <p>I am new to .net/jquery programming. Hopefully someone can help me. Thanks!</p>
    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.
 

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