locked
Document.getElementBYId returns 'null' in Remote site only RRS feed

  • Question

  • User269846090 posted

    I have a big issue with controls clientId.

    I have a html table, and adding rows dynamically from my code behind there is no problem.

    when i run in LOCAL it generates the prefix with mt RowId like,

    ContentPlaceHolder1_tr1

    ContentPlaceHolder1_tr2

    and if i check it like, alert(Document.getElementById('ContentPlaceHolder1_tr2'));

     i am getting [object HtmlRowElement] in alert.

    so i can access that Id.

    In LIVE, the id generates like,


    ct100_ContentPlaceHolder1_
    tr1

    ct100_ContentPlaceHolder1_tr2

    so i check like,.

    alert(Document.getElementById('ct100_ContentPlaceHolder1_tr2'));

    i am getting only null value.

    So i cant access that id.,

    How to solve this.,

    The rowIds are comes from code behind, so i can't give it like

    <%=rowId.ClientID%>.

    So pls donot advise to get client Id like above,

    pls assist me to the above Issue why the alert gets null value in LIVE.

     

    Monday, March 19, 2012 7:50 AM

Answers

  • User71929859 posted

    What is the .net version you are using? If you are using a framework greater than 4.0, try by setting the ClientIDMode="Static" for the row.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 20, 2012 12:54 PM

All replies

  • User-1360095595 posted
    You could, potentially, register the script from code behind where you can use ClientID.
    Monday, March 19, 2012 8:08 AM
  • User551462331 posted

    you should open the web page on live... and go to View source

    in html source, check what is the id of that <tr id="?">

    is it really like ct100_ContentPlaceHolder1_tr1?

    possibly it is not.... check what is the id and you would understand the issue

    hope this helps...

    Monday, March 19, 2012 8:10 AM
  • User269846090 posted

    Thanks Mr.

    but I have call the javascript function like below format.

    Is this correct?

    HtmlAnchor objAnchor = new HtmlAnchor();
    objAnchor.ID = "a|" + subCatId;
    objAnchor.InnerHtml = "Delete";
    objAnchor.HRef = "javascript:deleteCategory('" + subCatId + "','"+prefix+"" + rowId.ToString()+"','" + tblCategories + "')";

    Monday, March 19, 2012 8:13 AM
  • User269846090 posted

    Thanks 

    kedarrkulkarni.,

    I hace check the PageSource, Its also display the same Id as i measured.

    var tbl = document.getElementById("ctl00_ContentPlaceHolder1_tblCategories");

    RemoveSubCategory("ct100_ContentPlaceHolder1_" + rowId, pSubCatId);

    Monday, March 19, 2012 8:16 AM
  • User71929859 posted

    What is the .net version you are using? If you are using a framework greater than 4.0, try by setting the ClientIDMode="Static" for the row.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 20, 2012 12:54 PM