1

Why doesn't this work?

 <input type="button" id="btnAccept" value="Accept" onclick='<%# String.Format("accept('{0}','{1}','{2}','{3}-{4}');", Container.DataItem("PositionID"), Container.DataItem("ApplicantID"), Container.DataItem("FullName"), Container.DataItem("DepartmentName"), Container.DataItem("PositionTitle"))%>' />

The onclick doesn't do anything.

3
  • Is there an accept() function in your Javascript? Commented Apr 29, 2013 at 23:05
  • 1
    what's the generated html look like? Is there a js error? Commented Apr 29, 2013 at 23:05
  • 1
    What error do you get in the console? Commented Apr 29, 2013 at 23:21

1 Answer 1

3

Your best bet is to look at the generated HTML. I think it's a really good habit to check the generated HTML in text format and how it renders on-screen, all the time. Besides errors such as this (which can easily be spotted in the generated HTML), it will help you catch other possible invalid uses of HTML which may render as intended in one browser while rendering terribly in another. HTML rendering engines employ many tricks to try and make invalid HTML look okay.

Anyway, all things aside (such as, assuming accept(...) exists, and all other calls in the tag are correct) I think the issue you are having is as follows:

onclick='<%# String.Format("accept('{0}','{1}','{2}','{3}-{4}');", ... )%>'

This line is probably going to evaluate to look something like this:

onclick='accept('{0}','{1}','{2}','{3}-{4}');'

With all single quotes, all the onclick attribute will see is onclick='accept(' which is not a valid javascript method call. You're going to want to use the "" strings, which you can embed in the format string by escaping them.

String.Format("accept(\"{0}\",\"{1}\",\"{2}\",\"{3}-{4}\");", ... )

Then, you should be able to get the correct combination of ' and " within the attribute:

onclick='accept("{0}","{1}","{2}","{3}-{4}");'
Sign up to request clarification or add additional context in comments.

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.