Codebehind vs inline javascript

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

Hi All,

what is the difference of me putting in this onclick event in the
actual asp.net page as such
onclick="checkFieldStatus(document.forms[0].ctxtMCAmt, this.checked);"

compared to me putting this,
cbMC.Attributes.Add("onclick", "checkFieldStatus('ctxtMCAmt.ClientID',
this.checked);");

in the codebehind? What do I gain by registering this attribute in code
behind? I added this to a checkbox control by the way and wanted to
disable the another field once checkbox is not clicked.

Thanks,
JammingJ
 
In effect, there isn't much difference.

The second method is preferable as asp.net will ensure the client id is
properly set. Also, it keeps your application that little bit more
browser independent. In my opinion, it is easier to read and keeps
functionality separate from design markup.
 
Back
Top