0
<a id='aApp' runat='server' title='Approve' onclick='return OpenAppWin("<%#Eval("ID1") %>",
"<%#Eval("ID2") %>","<%#Eval("NAME") %>")' class='label' href='#'>Approve</a>

I need to pass 3 parameters as querystring to iframe, reason I am using runat='server' with anchor is to show user they can't click this link until they submit "remarks" which I am doing at server side i.e. disable link. Onclick I get this error Please advice any alternative or how to fix this error ?

Saleem
  • 3
  • 4
  • use `ctrl+k` for proper formatting of code. – Sagar V Apr 05 '17 at 06:38
  • Which error thrown when the anchor link being clicked? Also how `OpenAppWin` method defined? – Tetsuya Yamamoto Apr 05 '17 at 06:42
  • ctrl+k+d works for formatting code on VS2008, but that's not the issue exactly, its a simple Jscript function with 3 param. I can run the code but error comes when I click link – Saleem Apr 05 '17 at 06:43
  • error is : SyntaxError: missing ) after argument list return OpenAppWin("<%#Eval("ID1") %>","<%#Eval("ID2") %>","<%#Eval("NA... – Saleem Apr 05 '17 at 06:44
  • function OpenAppWin(ID1, ID2, name) { var oWnd; oWnd = $find('<%= mdlPopApprove.ClientID %>'); if (ID1 != '' && oWnd != null) { oWnd.setUrl("../ContextMenus/Approve.aspx?ID=" + ID1 + "&PLID=" + ID2 + "&PL=" + name); oWnd.add_close(OnWindowClose); oWnd.show(); } } @TetsuyaYamamoto – Saleem Apr 05 '17 at 06:46
  • Seems that one of the `Eval` method in `return OpenAppWin("<%# Eval("ID1") %>", "<%# Eval("ID2") %>", "<%# Eval("NAME") %>")` interpreted as plain string instead of giving ID, hence throwing JS syntax error. Can you give detail how `ID1`, `ID2` & `NAME` passed to page from code-behind? – Tetsuya Yamamoto Apr 05 '17 at 06:55
  • ID1,ID2 & NAME are Datakeynames from Grid- @TetsuyaYamamoto – Saleem Apr 05 '17 at 07:13

1 Answers1

0

You are enclosing double quotes withing double quote, using single and double quotes combination to avoid that.

onclick="return OpenAppWin('<%#Eval("ID1")%>','<%#Eval("ID2") %>','<%#Eval("NAME") %>');"

Edit based on comments, binding javascript event on server side

Bind javascript event in RowDataBound event on server side.

void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
      HyperLink link = (HyperLink)e.FindControl("aApp");
      link.Attribute.Add("onclick", ="return OpenAppWin('"+ DataBinder.Eval(e.Row.DataItem, "ID1") + "','" + DataBinder.Eval(e.Row.DataItem, "ID2") + "', '" + DataBinder.Eval(e.Row.DataItem, "Name") + "');"
  }
}
Adil
  • 146,340
  • 25
  • 209
  • 204
  • got this error on trying above syntax Parser Error Message: The server tag is not well formed. – Saleem Apr 05 '17 at 07:04
  • Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The server tag is not well formed. @Adil – Saleem Apr 05 '17 at 08:02
  • Yes I did, @Adil. – Saleem Apr 05 '17 at 08:09
  • when working with without runat='server' it works. but my requirement is to disable link server side based on condition. @Adil – Saleem Apr 05 '17 at 08:10
  • If it is server side then try to bind event on RowDataBound event – Adil Apr 05 '17 at 08:15
  • Good to know you did it!. – Adil Apr 05 '17 at 08:33