---
title: "Javascript Object Required using JavaScript and C#"  
description: "Javascript Object Required using JavaScript and C#"  
author: "E E Cummings"  
published: 2013-10-14  
updated: 2013-10-14  
canonical: https://www.mindstick.com/forum/1669/javascript-object-required-using-javascript-and-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Javascript Object Required using JavaScript and C#

I am checking the email Id of the user during [registration](https://www.mindstick.com/articles/23222/bonuses-of-casino-online-free-and-with-registration) to it is valid or not I am using the Javascript.I am [getting the value](https://www.mindstick.com/forum/182/problem-in-getting-the-value-from-array-by-using-foreach-loop) of the Textbox in the function during [button click](https://www.mindstick.com/forum/790/form-gets-submiited-twice-on-button-click) and verifying it but during click of the button it shows [Microsoft](https://www.mindstick.com/articles/12301/microsoft-is-trying-to-kill-passwords) JScript [runtime](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) error: Object [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) error Can any one point out what would be wrong in my code,

**My [javascript Function](https://www.mindstick.com/forum/2090/send-data-from-asp-dot-net-code-behind-to-a-javascript-function) is,**

```
     var txt = document.getElementById("emailid").value;    if (txt != "") {        var at = "@"        var dot = "."        var lat = str.indexOf(at)        var lstr = str.length        var ldot = str.indexOf(dot)        if (txt.indexOf(at) == -1) {            alert("Invalid E-mail ID")            obj.focus()            return false        }        if (txt.indexOf(at) == -1 || txt.indexOf(at) == 0 || txt.indexOf(at) == ltxt) {            alert("Invalid E-mail ID")            obj.focus()            return false        }        if (txt.indexOf(dot) == -1 || txt.indexOf(dot) == 0 || txt.indexOf(dot) == lstr) {            alert("Invalid E-mail ID")            obj.focus()            return false        }        if (str.indexOf(at, (lat + 1)) != -1) {            alert("Invalid E-mail ID")            obj.focus()            return false        }        if (txt.substring(lat - 1, lat) == dot || txt.substring(lat + 1, lat + 2) == dot) {            alert("Invalid E-mail ID")            obj.focus()            return false        }        if (txt.indexOf(dot, (lat + 2)) == -1) {            alert("Invalid E-mail ID")            obj.focus()            return false        }        if (txt.indexOf(" ") != -1) {            alert("Invalid E-mail ID")            obj.focus()            return false        }    }    return true}
```

## Replies

### Reply by Andrew Deniel

Check if your control is "runat=server" if so, the rendered html control name should be something like: #ctl00_ContentPlaceHolderMain_emailid.

Try changing this:

var txt = document.getElementById("emailid").value;

to this:

var txt = document.getElementById('<%=emailid.ClientID %>').value;

The ClientID will give you the full name in case the control is inside a content panel.

On the other side you are accessiong the property obj.focus()and I can't see obj declared inside the scope.


---

Original Source: https://www.mindstick.com/forum/1669/javascript-object-required-using-javascript-and-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
