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
 

nayanpatel

Active member
Joined
Nov 18, 2016
Messages
27
Location
ahmedabad
Programming Experience
3-5
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);".
 
Top Bottom