user1005497
user1005497

Reputation:

Too many characters in character literal?

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... :(

Upvotes: 5

Views: 39009

Answers (3)

Mathieu
Mathieu

Reputation: 3083

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>

Upvotes: 16

sq33G
sq33G

Reputation: 3360

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.

Upvotes: 13

ChrisBD
ChrisBD

Reputation: 9209

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>

Upvotes: 0

Related Questions