1
<asp:LinkButton ID="lnkBtn" runat="server" CssClass="csstab" Text='<%#Eval("Name")%>'
OnClientClick="return ShowInEditMode('<%#Eval("ID") %>')"></asp:LinkButton>

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.

The server tag is not well formed. LinkButton inside repeater

ND's
  • 2,155
  • 6
  • 38
  • 59

3 Answers3

2

Your OnClientClick event is having some wrong things.

use OnClientClick in the following way

OnClientClick='<%# string.Format("javascript:return ShowInEditMode({0})", Eval("ID"))%>'
Kamran Ajmal
  • 292
  • 3
  • 17
  • it should call. just put a debugger in javascript function and while running the page, click that button which is calling this method and check that Debugger is called or Not ? – Kamran Ajmal Oct 23 '13 at 06:23
  • this solution is not gona work because the return ShowInEditMode({0}) needs an other single quote :) around {0} it should be like ' string.Format("javascript:return ShowInEditMode('{0}')", Eval("ID")) which will give you the same error – Kiarash Oct 23 '13 at 06:35
  • i am using this code in almost 25 pages on my application with single or multiple parameters and i am not getting any error. – Kamran Ajmal Oct 23 '13 at 06:47
  • @KamranAjmal , the output I am getting is the same as Kiarash: e.g. return ShowInEditMode(123). It should be ShowInEditMode('123'). How do we do that? – Ciaran Gallagher Feb 04 '14 at 14:26
1

Well use this in html bit

<asp:LinkButton ID="lnkBtn" runat="server" CssClass="csstab" Text='<%#Eval("Name")%>' OnClientClick='<%#CreateShowInEditModeMethod(Eval("ID")) %>'></asp:LinkButton>

Then define this in your code behind

 protected string CreateShowInEditModeMethod(string str)
 {
        return String.Format("return ShowInEditMode('{0}');", str);
 }

let me know if did not solved :)

Kiarash
  • 1,701
  • 2
  • 16
  • 20
0

Replace external double quotes with single and & Eval quotes to double will work.

change onClientClick to:

OnClientClick='return ShowInEditMode("<%#Eval("ID") %>")'
Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110