0

The following C#:

SelectLink.Attributes.Add("onclick", String.Format("javascript:{0});", this.ClientScript.GetPostBackEventReference(this, "ad")));

(some omitted for clarity)

Appears to generate an href which has dropped the ';'. This causes validation errors in Internet Explorer, where it claims there is a missing ';'. I presume this is in the href. Why does it do this and how can I solve it?

<a href="javascript:__doPostBack('ctl00$MainContent$CR002,DNTL,T1.1','')" id="ctl00_MainContent_CR002,DNTL,T1.1" onclick="javascript:__doPostBack('__Page','ad'));">Click me</a>
deed02392
  • 4,799
  • 2
  • 31
  • 48

1 Answers1

2

You wrote "javascript:{0});" - just remove the closing parenthesis:

SelectLink.Attributes.Add("onclick", String.Format("javascript:{0};", this.ClientScript.GetPostBackEventReference(this, "ad")));
David Hoerster
  • 28,421
  • 8
  • 67
  • 102
cycaHuH
  • 3,240
  • 1
  • 14
  • 11