ASP.net generating invalid href

118 Views Asked by At

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>
1

There are 1 best solutions below

0
On BEST ANSWER

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

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