0

I'm writing a bit of aspx code to call a JavaScript function from a server control. Here's the JavaScript:

<script type="text/javascript">
    function checkInfoPortalUnpin(portalareaid) {
        if(portalareaid == 1) {
            alert('a message');
        }
    }
</script>

And here's the calling aspx code:

<asp:ImageButton OtherFields="omitted..."
   OnClientClick='checkInfoPortalUnpin(<%# Eval("PortalAreaID") %>);' />

When I view the source of that line in the browser (IE8) it is rendering as this:

... onclick="checkInfoPortalUnpin(&lt;%# Eval(&quot;PortalAreaID&quot;) %>);"

and I get a syntax error when I click on the ImageButton. I know the OnClientClick does work because if I replace the <%# ... %> with a hard-coded '1' the function runs fine. Am I missing something?

2

2 Answers 2

1

Use this :

... OnClientClick="checkInfoPortalUnpin('<%# Eval(\"PortalAreaID\") %>');" ...

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

4 Comments

That doesn't work because the " is used inside the main set of ". It gives a "Server tag is not well formed" error.
You're saying that this does not work: <asp:ImageButton otherFields="omitted..." OnClientClick="checkInfoPortalUnpin('<%# Eval(\"PortalAreaID\") %>');' /> ?
What you've posted now might work, now you've put the \" in. Before the edit there were no escape characters.
yep, agree. i missed the extra " in context.
0

Just use:

<asp:ImageButton runat="server" OnClientClick="checkInfoPortalUnpin('<%# Eval(\"PortalAreaID\") %>');" />

You forget to put single quote outside the server tag.

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.