Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

This is what i m trying. calling the function of the inline js. but i didn't working.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="javascript_Tutorials.WebForm1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>javaScript Tutorials</title>
        <script type="text/javascript" language="javascript">
            function objects() {
                alert("Well come");
            }
        </script>

    </head>
    <body>
        <form runat="server" id="myform">
        <asp:Button onclick="<% objects(); %>" runat="server"  />
        </form>

    </body>
    </html>

and have the following error:

CS1061: 'ASP.webform1_aspx' does not contain a definition for 'objects' and no extension method 'objects' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)

share|improve this question
I think you're looking for onclientclick. Anyway "it doesn't work, here's my code" is not how it's done. – CodeCaster Mar 21 at 11:02

marked as duplicate by CodeCaster, ChrisF Mar 21 at 11:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers

Use Button.OnClientClick instead on onclick to register client side javascript event and assign some id to button. The onclick is used to register server side event.

   <asp:Button  id="yourButtonID"  runat="server" OnClientClick="objects();" />
share|improve this answer
i have low reputation. thats why i couldn't give you the vote. but thnx a lot for urgent help... – user2147280 Mar 21 at 11:04

Try This>>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>javaScript Tutorials</title>

</head>
<body>
    <form runat="server" id="myform">
    <asp:Button onclick="<% objects(); %>" runat="server"  />
    </form>

</body>
</html>
<script type="text/javascript" language="javascript">
            function objects() {
                alert("Well come");
            }
        </script>

Pasting script at last also works when above code does not works.

share|improve this answer

You can you the following code:-

<asp:Button ID="Button1" OnClientClick="return objects();" runat="server"  />
share|improve this answer
Remove Parenthesis after function call

<asp:Button ID="Button1" OnClientClick="objects;" runat="server"  />
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.