Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys i have used linkbutton in the gridview itemtemplate
but i got this error
"The server tag is not well formed."
i'm checked all close tags but i think is ok

    OnClientClick='return confirm('"وضعیت پلن به"+ <%#Eval("pStatus").ToString().Equals("0") ? "فعال تغیر کند؟" : "به غیر فعال تغیر کند؟" %>+"')"
    CommandArgument='<%#Eval("id") %>' 
    CssClass='label label-<%# Eval("pStatus").ToString().Equals("0") ? "danger" : "success" %>'> 
    <%# Eval("pStatus").ToString().Equals("0") ? "فعال" : "غیرفعال" %> 

What I have tried:

searching on another posts on the internet and can't find anything
Richard MacCutchan 5-Jan-24 4:08am    
I am not an asp expert, but I think you may have mis-matched quotes in the OnClientClick attributes.

1 solution

Aside from the mis-matched quotes, adding an unconditional return to the OnClientClick will break the behaviour of the LinkButton, since it relies on executing additional JavaScript after that code has executed.

    id="lnkBtnDelete" runat="server"
    OnClientClick='<%# "if(!confirm(&quot;وضعیت پلن به" + (Eval("pStatus").ToString().Equals("0") ? "به غیر فعال تغیر کند؟" : "فعال تغیر کند؟") + "&quot;)){return false;}" %>'
Share this answer
uniservice333 5-Jan-24 4:48am    
ty richard but i got another error with your code "CS1056: Unexpected character '؟'"
and in second quot in aspx page
Richard Deeming 5-Jan-24 4:53am    
Maybe it's the encoding of the ASPX file?

You could try building the string in the code-behind:
public static string BuildDeleteConfirmation(string pStatus)
    return "if(!confirm(\"وضعیت پلن به" + (string.Equals(pStatus, "0") ? "به غیر فعال تغیر کند؟" : "فعال تغیر کند؟") + "\")){return false;}";
OnClientClick='<%# BuildDeleteConfirmation(Eval("pStatus", "{0}")) %>'
uniservice333 5-Jan-24 5:26am    
ty dude resolved 👍👍👍

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900