Javascript Error: Object Required: ASP.NET

jmohan

Member
Joined
Jun 6, 2008
Messages
7
Programming Experience
Beginner
Hi everyone,

I am unable to find out the Id in Javascript from the server control.

I have used the following code,

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkboxHeader" runat="server" AutoPostBack="false" onclick="javascript:selectallrow(this.Id);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkboxBody" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

function selectallrow(Id)
{
var getobj=document.getElementById(Id).value;
alert(getobj);
}

I have replaced also the following script, but nothing works,
var getobj=document.getElementById("<%=Id.ClientID %>").value;

But 'Object required error occurred'
Please provide me a solution

thanks in advance,

Mohan J
 
javascript:selectallrow(this.Id)
Javascript is case-sensitive, there is no Id property, but there is a id property. Only this can be passed also as element reference.
 
Javascript is case sensitive. In your code you used onclick="javascript:selectallrow(this.Id);" but there is an id with ‘ID’ in capital letters.


<asp:CheckBox ID="chkboxHeader" runat="server" AutoPostBack="false" onclick="javascript:selectallrow(this.Id);" />

So,you have to use onclick="javascript:selectallrow(this.ID);".
 
Back
Top