5

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

3
  • 2
    Did you try to replace the inner text, by a text property : <asp:LinkButton ID="LinkButton1" OnClick="DivAc('griddiv')" Font-Size="Smaller" runat="server" CommandName='<%# Eval("harf").ToString().ToUpper()%>' Text='<%# Eval("harf").ToString().ToUpper() %>' /> ?
    – Steve B
    Oct 27, 2011 at 7:29
  • By the way, you can't use generic function for OnClick event handler. Oct 27, 2011 at 7:38
  • Hi there people, thanks for your quick replies but I guess, problem is because of this : OnClick="DivAc('griddiv')" because when I remove this part it works???...
    – user1005497
    Oct 27, 2011 at 7:42

3 Answers 3

16

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>
1
  • Thanks Mathieu... Sorry this is my fault :(
    – user1005497
    Oct 27, 2011 at 8:05
13

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.

1
  • Thanks sq33G Onclientclick solve the issue... All my fault sorry for occupying... Thanks all!
    – user1005497
    Oct 27, 2011 at 8:04
0

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>
2
  • Your suggestion will result in no text for the LinkButton.
    – Tim
    Oct 27, 2011 at 7:35
  • Hi there people, thanks for your quick replies but I guess, problem is because of this : OnClick="DivAc('griddiv')" because when I remove this part it works???...
    – user1005497
    Oct 27, 2011 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.