By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 916 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.

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

P: 1
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.

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () {
  2.  
  3.     var myButton = document.getElementById('<%= btnsubmit.ClientID %>');
  4.  
  5.     myButton.onclick = function () {
  6.  
  7.         var script = document.createElement("script");
  8.         $.ajax({
  9.             url: "testmenow.aspx",
  10.             data: null,
  11.             success: function (data) {
  12.                 $("#parttable").html(data);
  13.             }
  14.         });
  15.         return false;
  16.     }
  17.  
  18.  
  19. });
  20.  
  21.  
  22. ASP page
  23. <div id="parttable"> </div> <asp:Button ID="btnsubmit" runat="server" Text="click me" name="btnsubmit" />
Apr 26 '14 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
that simply means that JS failed to locate your myButton element.
Apr 28 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.