The server tag is not well formed

余生长醉 提交于 2020-01-04 03:38:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!