Codebehind vs inline javascript

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
 
C

cannontrodder

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top