Solved

Object Required run time error after OnClientClick event is added

Posted on 2011-09-03
4
513 Views
Last Modified: 2012-05-12
I have a Save button working well. After I added an OnClientClick event to check s few required fields, I got error "Microsoft JScript runtime error: Object expected". I checked each field name in the javascript hanlder function, those reuired fields names are correct. I cannot figure out why it happens. Please help.

<asp:Button ID="btnSaveDev" runat="server" Text="Save" Width="120px" onclick="btnSaveDev_Click" OnClientClick="return (evalBeforeSave());"/>

<script type="text/javascript" language="javascript">

       function evalBeforeSave()
       {  
            if (document.getElementById("<%=txtno.ClientID%>").value=="")
            {
                alert("Id # can not be blank");
                document.getElementById("<%=txtno.ClientID%>").focus();
                return false;
            }            
            if (document.getElementById("<%=txtcode.ClientID%>").value=="")
            {
                alert("Code can not be blank");
                document.getElementById("<%=txtcode.ClientID%>").focus();
                return false;
            }
            ...
           return true;
    }

</script>
0
Comment
Question by:minglelinch
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
navneethegde earned 250 total points
ID: 36478108
HI!

try writing
<asp:Button ID="btnSaveDev" runat="server" Text="Save" Width="120px" onclick="btnSaveDev_Click" OnClientClick="evalBeforeSave();"/>

thanks!
0
 
LVL 17

Assisted Solution

by:Carlos Villegas
Carlos Villegas earned 250 total points
ID: 36478135
Hello, where is declared the evalBeforeSave() function? is in the same aspx page? if not, you need to declare that function in the same page, so the control names can be dynamically rendered...  if yes, can you post the full rendered html code of your page?

Regards.
0
 
LVL 1

Assisted Solution

by:minglelinch
minglelinch earned 0 total points
ID: 36478144
Thanks for the comment. I just found it because of a piece of previous code problem causing the error.

But your suggestion has a better coding style.
0
 
LVL 1

Author Closing Comment

by:minglelinch
ID: 37790285
Thanks for comments.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form Data Disappears Using Back Button 4 21
Upgrade code from VS 2010 to VS 2015 7 33
ASP.NET - Why is accordion not working? 3 50
C# XML Get Values 4 35
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question