Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Javascript Error: Object Required: Asp.net

    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
    Last edited by jmohan; 12-16-2011 at 06:24 AM.

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,718
    Thanks
    41
    Thanked 191 Times in 190 Posts
    first a few things to try-
    have you run debug and seen what values are?
    set break point on the script call and in immediate window check value of the id being passed by the onclick function. Also I do not see any field value="something" so how can you target that id's value if it does not exist? But I think the more underlying problem is probably that <asp: objects "onclick" events target the code behind function... try OnClientClick="" ... i think there are probably a few things you will need to debug.

    Edit: as a side note if you set the break points and are not using IE for default browser, I do not think visual studio will break on it- I have had problems w/ this in the past trying to us chrome as default browser. *the only reason IE is my default browser

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •