Javascript/ Ajax Error. I can't figure it out.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leathalassassin
    New Member
    • Apr 2014
    • 1

    Javascript/ Ajax Error. I can't figure it out.

    I have a JavaScript in an external page and the script reference in the master page of asp.net. I am getting an error I can not figure out.

    "Now it is saying that JavaScript runtime error: Unable to set property 'onclick' of undefined or null reference."

    Any tips on how to fix this would be greatly appreciated.

    Code:
    $(document).ready(function () {
    
        var myButton = document.getElementById('<%= btnsubmit.ClientID %>');
    
        myButton.onclick = function () {
    
            var script = document.createElement("script");
            $.ajax({
                url: "testmenow.aspx",
                data: null,
                success: function (data) {
                    $("#parttable").html(data);
                }
            });
            return false;
        }
    
    
    });
    
    
    ASP page
    <div id="parttable"> </div> <asp:Button ID="btnsubmit" runat="server" Text="click me" name="btnsubmit" />
    Last edited by Rabbit; Apr 27 '14, 05:18 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that simply means that JS failed to locate your myButton element.

    Comment

    Working...