views:

1234

answers:

2

So, I want to use jquery to set the text of a button, depending on the value of a property in the current row of a repeater.

I need to call a function in the code-behind to map the value to the text the button should have. So, I need to pass to my foo function, the string value of the UserStatus property for the current item in the repeater.

I want to do the following, although this syntax is obviously not correct:

<asp:Repeater ID="dgCustomer" runat="server">
  <ItemTemplate> 
    <input id="rb" name="rb" type="radio" onclick='javascript:$("input.magicbutton").val("<%= foo(DataBinder.Eval(Container.DataItem, "UserStatus")) %>");'

If the codebehind contains the following method definition:

protected string foo(string status)

What is the correct syntax to call foo with an Item value from the repeater?

+2  A: 

Switch the <%= with <%# and it looks like you should be good to go.

Tom Jelen
Didn't realise I could do that, thanks.
Winston Smith
<%# is for expressions to be evaluated while you are databinding. <%= is pretty much equivalent to Response.Write and can be used almost anywhere outside of databinding contexts.
Tom Jelen
A: 

The only issue I see with that code snippet is that you need to use a databinding nugget (<%# ... %>) instead of the expression nugget (<%= ... %>).

You may run into issues with surrounding your nugget with double quotes, since it contains double quotes already. You may have to have foo return the value in quotes, or even have have foo just return the whole onclick event...

bdukes