I have a hiddenfield inside a repeater control and a button outside the repeater control. below is the asp.code that i have.
<asp:Repeater ID="rptAccordian" runat="server" OnItemDataBound="rptAccordian_ItemDataBound">
<ItemTemplate>
<div class="s_panel">
<h1>
<a href="#" data-content="Tool tip"><%# Eval("Name") %></a>
</h1>
<div>
<p>
<small><span style="font-family: 'Segoe UI'; font-weight: bold;">Category Objective: </span><span style="font-family: 'Segoe UI'"><%# Eval("Objective") %></span></small>
</p>
<p>
<small><span style="font-family: 'Segoe UI'; font-weight: bold;">Category Riskscore: </span>
<code><%# Eval("Score") %><span>%</span></code></small>
</p>
<p>
<code>
<img src="Content/img/add.png" /><asp:LinkButton ID="Add" runat="server">Add Question</asp:LinkButton>
</code>
</p>
<asp:HiddenField ID="hdnCategoryID" runat="server" Value='<%# Bind("CategoryID") %>' />
</div>
</ItemTemplate>
</asp:Repeater>
<div id="modalpopup">
<asp:Button ID="btnInsertQuestion" runat="server" Text="Save" OnClick="btnInsertQuestion_Click" />
</div>
My Backend code is as follows.
protected void btnInsertQuestion_Click(object sender, EventArgs e)
{
HiddenField hf = (HiddenField)rptAccordian.FindControl("hdnCategoryID");
catID = Convert.ToInt16(hf.Value);
Response.Write("ID is") + catID;
}
There are 13 repeaters and each repeater will have different CategoryID for it. I have a Link Button called Add inside each repeater and when I press that button I will have a modal popup open and it will have a button. On clicking that button I need to display the appropriate CategoryID which belongs to that repeater control in which I clicked the ADD link button.
However, the hiddenfield hf is showing as null and I'm not able to get the value of the hiddenfield of that accordion.
I have acheived my answer using jQuery. I found the control hdnCategoryID and its value using jQuery and i assigned that value to a new hidden field and retrieved that value to my click event.