PrateekSaluja PrateekSaluja - 4 years ago 165
ASP.NET (C#) Question

How to pass a hidden field value on javascript function inside repeater control

I tried a lot but couldn't figure it out. I wanted to pass data on my javascript function.
I am saving data on hidden filed. what I want as soon I click on my button it will call javascript function & pass my hidden field vlaue.

<asp:Repeater ID="rptGallary" runat="server" >
<asp:HiddenField ID="hfsportsmanfeedid" runat="server" value='<%# DataBinder.Eval(Container.DataItem,"SportsmanFeedId") %>'/>
<asp:Button ID="btnLike" runat="server" Text="Like" OnClientClick="Test("How to pass here"));" />

Thanks for your help.

Answer Source

You just need to pass the clicked element on Test button click

Try with this code:


<asp:Button ID="btnLike" runat="server" Text="Like" 
OnClientClick="Test(this);" />


function Test(element){
  var $btn = $(element) // Gets clicked button
  var hiddenBValue = $btn.prev().val(); // Gets hidden element value


  • prev()
  • This should work!

    Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download