Solved

Object Required run time error after OnClientClick event is added

Posted on 2011-09-03
4
509 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for comments.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now