Jay
Jay

Reputation: 137

How to call JavaScript function when binding data to asp.Net Repeater

I'm trying to call a javascript function when repeater binding from the code behind.

Here is the sample code that i'm tring to call javascript function:

<asp:Repeater ID="summeryR" runat="server">
  <ItemTemplate>
    <div class="question-head">
      <p><%# Eval("QuestionText") %></p>
    </div>
    <div class="question-respond">
      <p><%# Eval("Label", "checkSkipQuestion()") %></p>
    </div>
  </ItemTemplate>
</asp:Repeater>

here is the javascript function:

 function checkSkipQuestion()
 {
  alert("checkSkipQuestion");
 }

Upvotes: 0

Views: 1673

Answers (2)

Manish
Manish

Reputation: 1

          <p><%# Eval("Label", "<script type=text/java-script> alert('Hi..') ; 
    </script>") %></p>

if it is not work then remove dash from type.

Upvotes: 0

jwatts1980
jwatts1980

Reputation: 7356

This can not be done.

The IIS server is processing the repeater and building an HTML table. This happens during compile time of the page. Once the page is compiled, and completed as HTML by the server, it is sent to the browser. At that point, any JavaScript can be run. In other words, you cannot call a JavaScript function while the repeater is building the table.

Upvotes: 1

Related Questions