3

Here is my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient._Default" %>
<!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></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js" />
    <script type="text/javascript" language="javascript">
        var count = 0;
        function Start()
        {
            setInterval("ReadNotification()", 1000);
        }
        function ReadNotification()
        {
            alert(++count);
        }
    </script>
</head>
<body onload="return Start();">
</body>
</html>

I just run this code and received a classic error:

Microsoft JScript runtime error: 'Start' is undefined

I dont't know why, because I really defined this method. How can I solve this problem ?

Thank you very much.

1 Answer 1

4

Looks like the script tag for jquery is not closig properly unless you put a tag to close it, which renders those objects not readable, which gives you the error.

Code below, hope this helps.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient._Default" %>
<!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></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
    </script>
    <script>
        var count = 0;
        function Start()
        {
            setInterval("ReadNotification()", 5000);
        };
        function ReadNotification()
        {
            alert(++count);
        };
    </script>
</head>
<body onload="return Start();">

</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much, it really works fine! But why? I remembered that people tell me that the script should close with '/>'. Not clear in my mind......
You got it Jeffrey, I'm not so sure, why this is the case but when you have runat=server, it screws up the opening/closing brackets. But if you explicitly set them, it renders correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.