Too many characters in character literal?

ぃ、小莉子 提交于 2019-12-07 05:43:55

问题


Can you tell me please what is wrong with this code??? About to getting crazy!!!

<asp:LinkButton ID="LinkButton1" OnClick="DivAc('griddiv')" Font-Size="Smaller"  runat="server" CommandName='<%# Eval("harf").ToString().ToUpper()%>'><%# Eval("harf").ToString().ToUpper() %></asp:LinkButton>

Error: Too many characters in character literal... :(


回答1:


Is DivAc('griddiv') a javascript function? Then you have to use OnClientClick instead of OnClick.

OnClick is reserved for .NET functions. With OnClientClick you generates the OnClick-attribute in HTML.

This is probably a bit confusing.

So this is what you have to do:

<asp:LinkButton ID="LinkButton1" OnClientClick="DivAc('griddiv')" Font-Size="Smaller"  runat="server" CommandName='<%# Eval("harf").ToString().ToUpper()%>'><%# Eval("harf").ToString().ToUpper() %></asp:LinkButton>



回答2:


The immediate issue is that you placed a string (griddiv) in character quotes (a single quote, in C#, is for a single character only). You would need to write something like OnClick="DivAc(\"griddiv\")"

BUT

OnClick is a server-side event handler that takes the name of a public or protected function that takes (object,EventArgs) and returns void. So this won't compile anyway.

Where is DivAc? In JavaScript? If so, you want OnClientClick, in which case you can leave the single and double quotes as they are.




回答3:


I think that your error is here:

CommandName='<%# Eval("harf").ToString().ToUpper()%>'><%# Eval("harf").ToString().ToUpper() %></asp:LinkButton>

I think that its should be:

CommandName='<%# Eval("harf").ToString().ToUpper()%'></asp:LinkButton>


来源:https://stackoverflow.com/questions/7912819/too-many-characters-in-character-literal

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