Solved

Object Required run time error after OnClientClick event is added

Posted on 2011-09-03
4
514 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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