Solved

Object Required run time error after OnClientClick event is added

Posted on 2011-09-03
4
511 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.net and XML report from SCCM 5 23
MediaHelp 4 23
Batch file or script with password 22 43
Help with exporting to excel 4 27
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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