0

I have a js function which needs to be called when the page is completely loaded. I tried calling the function on body as below

onload="GridExpInfo_ClientInsert()"

but it doesn't works as expected, it gets called before the page is fully loaded.

UPDATE

Code:

function GridExpInfo_ClientInsert() {
        var rowVal = "0";                  // assigned variable with value as 0
        for (i = 0; i < GridExpInfo.Rows.length; i++) {
            rowVal = i;                   // assigning values which always takes the value of i
            if (GridExpInfo.Rows[i].Cells[7].Value == "" || GridExpInfo.Rows[i].Cells[7].Value == "0") {
                document.getElementById('GridExpInfo_ob_GridExpInfoBodyContainer_ctl33_' + rowVal + '_ctl00_' + rowVal + '_Button1_' + rowVal + '').style.display = "none";
            }
            else {
            }
        }
    }
Nad
  • 4,605
  • 11
  • 71
  • 160
  • Possible duplicate of [call a function after complete page load](http://stackoverflow.com/questions/11936816/call-a-function-after-complete-page-load) – Rajesh Nov 02 '16 at 06:19
  • Is some content in page is loaded through `AJAX` ? – Rayon Nov 02 '16 at 06:19
  • it should do it, what's unexpected? – Max Koretskyi Nov 02 '16 at 06:19
  • @Rayon: no, nothing is loaded thorugh `ajax` – Nad Nov 02 '16 at 06:19
  • You need to provide a [MCVE] and tell us what part of the code is being loaded after the load event fires. We can't tell you how to make the code wait for something when we don't know what the something is. – Quentin Nov 02 '16 at 06:22
  • @Quentin: My code works when I use it on other part. But When I am using it on load it doesn't works properly. I want to make it on page load. how to do that ? – Nad Nov 02 '16 at 06:25
  • @nad — The code you have should work "properly". Your question doesn't have enough information in it to tell why it does not. See my previous comment. You need a [MCVE]. You need to tell us what is loading after the load event fires. – Quentin Nov 02 '16 at 06:26
  • @Quentin: What happens is when the page is loaded, I get error as `GridExpInfo.Rows.length' is null or not an object`. So first time it gives me that error. I have updated the question – Nad Nov 02 '16 at 06:28
  • @Quentin: Sir, what else do you want. ? – Nad Nov 02 '16 at 06:29
  • A [MCVE]. That's a link. Click on it. Read it. (e.g. you haven't included any HTML. You haven't defined `GridExpInfo`) – Quentin Nov 02 '16 at 06:29
  • @Quentin: I am unable to produce the problem on my side as the controls are asp.net. But if you understand what I am explaining, I m sure you will guide me to solve this problem – Nad Nov 02 '16 at 06:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127148/discussion-between-nad-and-quentin). – Nad Nov 02 '16 at 06:35
  • 1
    Why should we be able to solve your problem when you can't even demonstrate it? – Quentin Nov 02 '16 at 06:35
  • @Quentin: You are correct, but see I have a grid what I want to show is when the page is loaded, I want to hide a button with some condition. I guess you can suggest me how to do this – Nad Nov 02 '16 at 06:36
  • Don't vaguely describe what you have. Show us a [MCVE] – Quentin Nov 02 '16 at 06:38
  • @Quentin: sir, can u come on chat, I can explain you their better – Nad Nov 02 '16 at 06:39
  • No. Provide a [MCVE] in the question. – Quentin Nov 02 '16 at 06:41

0 Answers0