onclick button event throws compiler error

Discussion in 'ASP .Net' started by wardy1975@gmail.com, Mar 17, 2006.

  1. Guest

    Hi all....looking for a bit of help here....I'm using an asp.net server
    side button, and trying to add an onclick event on the button to call a
    javascript function. However, I am trying to enter the onclick syntax
    directly in the html instead of via the attributes.add functionality
    (this is required due to the dynamic nature of how the buttons are
    added to the screen). The problem is, I get a compilation error when I
    try to load the page that the first word I have in the onclick
    definition "is not a member of " and my page name.

    So, if I had the code below in a webform called Webform4.aspx:

    <asp:button id="btnClearSubmit" onclick="testfn();" runat="server"
    commandname="submit" cssclass="test"
    text="Clear List">

    I get the compliation error:

    Compiler Error Message: BC30456: 'testfn' is not a member of
    'ASP.WebForm4_aspx'.

    Anyone ever run into this before? Am I doing something wrong? In my
    mind I would have thought that entering an onclick definition directly
    in the html should still work for server side buttons.

    Thanks
    , Mar 17, 2006
    #1
    1. Advertising

  2. That onclick in the server side tag refers to the server side method to run
    when the button postsback to the server. It's a declarative way of
    attaching a server side event handler. It is not the client side event to
    run.

    You need still add the client side one via Attributes.Add.

    <> wrote in message
    news:...
    > Hi all....looking for a bit of help here....I'm using an asp.net server
    > side button, and trying to add an onclick event on the button to call a
    > javascript function. However, I am trying to enter the onclick syntax
    > directly in the html instead of via the attributes.add functionality
    > (this is required due to the dynamic nature of how the buttons are
    > added to the screen). The problem is, I get a compilation error when I
    > try to load the page that the first word I have in the onclick
    > definition "is not a member of " and my page name.
    >
    > So, if I had the code below in a webform called Webform4.aspx:
    >
    > <asp:button id="btnClearSubmit" onclick="testfn();" runat="server"
    > commandname="submit" cssclass="test"
    > text="Clear List">
    >
    > I get the compliation error:
    >
    > Compiler Error Message: BC30456: 'testfn' is not a member of
    > 'ASP.WebForm4_aspx'.
    >
    > Anyone ever run into this before? Am I doing something wrong? In my
    > mind I would have thought that entering an onclick definition directly
    > in the html should still work for server side buttons.
    >
    > Thanks
    >
    Marina Levit [MVP], Mar 17, 2006
    #2
    1. Advertising

  3. Yea like Marina said: Specifically something like this will work for you:
    in the pageload of the form


    btnClearSubmit.Add.Attributes("Onclick", "testfn();");

    try that

    HTH,
    Tony


    "Marina Levit [MVP]" <> wrote in message
    news:...
    > That onclick in the server side tag refers to the server side method to
    > run when the button postsback to the server. It's a declarative way of
    > attaching a server side event handler. It is not the client side event to
    > run.
    >
    > You need still add the client side one via Attributes.Add.
    >
    > <> wrote in message
    > news:...
    >> Hi all....looking for a bit of help here....I'm using an asp.net server
    >> side button, and trying to add an onclick event on the button to call a
    >> javascript function. However, I am trying to enter the onclick syntax
    >> directly in the html instead of via the attributes.add functionality
    >> (this is required due to the dynamic nature of how the buttons are
    >> added to the screen). The problem is, I get a compilation error when I
    >> try to load the page that the first word I have in the onclick
    >> definition "is not a member of " and my page name.
    >>
    >> So, if I had the code below in a webform called Webform4.aspx:
    >>
    >> <asp:button id="btnClearSubmit" onclick="testfn();" runat="server"
    >> commandname="submit" cssclass="test"
    >> text="Clear List">
    >>
    >> I get the compliation error:
    >>
    >> Compiler Error Message: BC30456: 'testfn' is not a member of
    >> 'ASP.WebForm4_aspx'.
    >>
    >> Anyone ever run into this before? Am I doing something wrong? In my
    >> mind I would have thought that entering an onclick definition directly
    >> in the html should still work for server side buttons.
    >>
    >> Thanks
    >>

    >
    >
    Anthony Merante, Mar 17, 2006
    #3
  4. Guest

    Hi all....thanks for the replies. The problem with the use of the
    Add.Attributes syntax is that we do not know at design time how many
    buttons and the names of the buttons as we allow for the dynamic
    addition of server side controls in our rendering engine, so we cannot
    do this in the codebehind. So, we need to be able to do this in the
    html directly. The strange thing is, we have this working in other
    parts of the application where the onlick is simply written into the
    html, and it has no problem compiling or rendering or calling the
    javascript function then doing the postback. The code that works is as
    follows:

    <asp:button runat="server" id="btnSubmit" text="Save"
    commandname="submit" onClick="return ValidateForm(document.forms[0]);"
    cssclass="AddToBasket"></asp:button>

    Any thoughts on the discrepancy?
    , Mar 17, 2006
    #4
  5. raiderruler

    Joined:
    Jun 2, 2010
    Messages:
    1
    Try using OnClientClick

    I know this thread is old, but I had the same problem today. Have you tried using OnClientClick instead of OnClick? This was worked to fix it for me.
    raiderruler, Jun 2, 2010
    #5
    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.

Share This Page