Search code examples
javascriptasp.netascx

How can my user control get information from my aspx page


I have a user control and inside the user control, the code is trying to set up a pop up window and set a label value by

document.getElementById("ReportTitle").innerText = TitleText;

The id "ReportTitle" is defined in the aspx page as

<a id="ReportTitle" style="font-family:Verdana; font-weight.bold; font-size:9px; cursor:pointer">Ocean Cargo</a>

It's also trying to set up the URL and a visibility property the same way. I am receiving the error "Unable to set property 'innerText' of undefined or null reference.' My first thought is that it is trying to set the value before the first window has finished loading and I've tried using window.open on the function containing the call to getElementById but it didn't work. I'm trying to determine if that is the issue or if it is unable to obtain "ReportTitle" because it's on the aspx page.

Thank you.


Solution

  • I finally got it working. I had to change

    window.onload

    to

    document.onreadystatechange = function () {
        if (document.readyState == "complete") {
            InitSearch();
        }
    }