Codebehind vs inline javascript

Discussion in 'ASP .Net' started by JJ, Jul 28, 2006.

  1. JJ

    JJ Guest

    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
     
    JJ, Jul 28, 2006
    #1
    1. Advertising

  2. 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.
    JJ wrote:
    > 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
     
    cannontrodder, Jul 28, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary Brewer

    codebehind with no inline

    Gary Brewer, Jan 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    326
    Laidbak
    Jan 23, 2004
  2. Earl Teigrob
    Replies:
    1
    Views:
    340
    Scott Allen
    Jul 9, 2004
  3. xenophon

    Mix Inline and Codebehind?

    xenophon, Jan 19, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    530
    Steven Cheng[MSFT]
    Jan 20, 2006
  4. Abhi
    Replies:
    2
    Views:
    742
    E. Robert Tisdale
    Jul 3, 2003
  5. gr8oblivion
    Replies:
    0
    Views:
    527
    gr8oblivion
    Apr 16, 2007
Loading...

Share This Page