Solved

Object Required run time error after OnClientClick event is added

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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