问题
I have the following image button on the GridView and I want to call the OnClientClick to call javascript method with passing a parameter. I am getting Server Tag is not well formed error. I tried changing double quotes to single quote etc, still the same issue.
OnClientClick="return ConfirmOnDelete('<%#Eval("Name")%>');"
<asp:ImageButton ID="imgDelete" CommandName="Delete" ImageUrl="~/images/fbclose.png" AlternateText="Delete" runat="server" OnClientClick="return ConfirmOnDelete('<%#Eval("Name")%>');"/>
回答1:
You need to use single quotes around the OnClientClick property:
OnClientClick='return ConfirmOnDelete(<%#Eval("Name")%>);'
You also had an orphaned single quote after the Eval function. If you need to wrap the value that you're passing into the function with quotes, you can do this:
OnClientClick='return confirmOnDelete(\"<%#Eval("Name")%>\");'
回答2:
OnClientClick="return ConfirmOnDelete(<%#Eval("Name")%>') you only have one single quote at the end change it to
OnClientClick='return ConfirmOnDelete(<%#Eval("Name")%>)'
来源:https://stackoverflow.com/questions/7814383/the-server-tag-is-not-well-formed