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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top