0

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");
 }

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Jay: I cannot tell from your code example what it is that you are trying to accomplish. So the above answer is all the advice I can give for the moment.
Thanks @jwatts1980 for your explanation. I found a solution instead of using javascript function, that I can call code-behind function when data binding. ex-<%# this.DataBinder(Eval("Label") as string) %> like this. This works for me :)
0
          <p><%# Eval("Label", "<script type=text/java-script> alert('Hi..') ; 
    </script>") %></p>

if it is not work then remove dash from type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.