By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

onclick button event throws compiler error

P: n/a
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 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

<wa*******@gmail.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...
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 '06 #2

P: n/a
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]" <so*****@nospam.com> wrote in message
news:OI*************@TK2MSFTNGP10.phx.gbl...
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.

<wa*******@gmail.com> wrote in message
news:11**********************@j52g2000cwj.googlegr oups.com...
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 '06 #3

P: n/a
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 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.