referring to a third-party contol in window.onload

Discussion in 'ASP .Net Web Controls' started by dchillman, Oct 31, 2005.

  1. dchillman

    dchillman Guest

    I have a user control page (ascx) that contains a third-party spreasheet
    control. When the user clicks the insert button on the spreadsheet control,
    I am trying to pre-insert values into the new row. If I put the spreadsheet
    control directly on as aspx page, I can do this in the window.onload
    function. However, when the spreadsheet control in on an ascx page, I get an
    error that says the control is undefined.

    here is the code on the html page of the ascx.

    <script language="javascript">

    function window.onload()
    {
    //debugger
    var i;
    //var spreadRef = document.getElementById(FpSread1);
    var table = FpSread1.all("FpSpread1_viewPort").firstChild;
    for(i=1;i<=spreadRef.GetRowCount();i++)
    {
    if(table.rows.FpKey=="newRow")
    {
    alert("New Row");
    FpSread1.SetValue(i-1, 0, FpSread1.GetValue(i, 0));
    FpSread1.SetValue(i-1, 1, FpSread1.GetValue(i, 1));
    FpSread1.SetValue(i-1, 2, FpSread1.GetValue(i, 2));
    }
    }

    }
    </script>

    When the page loads, there is a yellow exclamation point that essentially
    states that
    "FpSpread1 is undefined".

    Is it possible to access a third party control within a user control on the
    clientside?

    Thanks for any help you can provide.
    --
    dchillman
    dchillman, Oct 31, 2005
    #1
    1. Advertising

  2. The reason you get the error that "FpSpread1 is undefined" is that when
    ASP.NET renders server controls it adds the namingcontainer id as a prefix to
    the control id.

    Instead of using the document.getElementById, try something like this:

    var table = findControl("FpSpread1");
    if (table !=null) //do all of the processing that you want

    and write a function as this:

    <script language="javascript">
    function findControl(ControlName)
    {

    var aTables = document.getElementsByTagName("table");
    if (aTables)
    { for (var i=0; i < aTables.length ; i++)
    {
    if (aTables.id.lastIndexOf(ControlName) == aTables.id.length -
    ControlName.length)
    {
    ret =aTables;
    }
    }
    }
    return ret;
    }
    </script>

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "dchillman" wrote:

    > I have a user control page (ascx) that contains a third-party spreasheet
    > control. When the user clicks the insert button on the spreadsheet control,
    > I am trying to pre-insert values into the new row. If I put the spreadsheet
    > control directly on as aspx page, I can do this in the window.onload
    > function. However, when the spreadsheet control in on an ascx page, I get an
    > error that says the control is undefined.
    >
    > here is the code on the html page of the ascx.
    >
    > <script language="javascript">
    >
    > function window.onload()
    > {
    > //debugger
    > var i;
    > //var spreadRef = document.getElementById(FpSread1);
    > var table = FpSread1.all("FpSpread1_viewPort").firstChild;
    > for(i=1;i<=spreadRef.GetRowCount();i++)
    > {
    > if(table.rows.FpKey=="newRow")
    > {
    > alert("New Row");
    > FpSread1.SetValue(i-1, 0, FpSread1.GetValue(i, 0));
    > FpSread1.SetValue(i-1, 1, FpSread1.GetValue(i, 1));
    > FpSread1.SetValue(i-1, 2, FpSread1.GetValue(i, 2));
    > }
    > }
    >
    > }
    > </script>
    >
    > When the page loads, there is a yellow exclamation point that essentially
    > states that
    > "FpSpread1 is undefined".
    >
    > Is it possible to access a third party control within a user control on the
    > clientside?
    >
    > Thanks for any help you can provide.
    > --
    > dchillman
    Phillip Williams, Oct 31, 2005
    #2
    1. Advertising

  3. dchillman

    dchillman Guest

    Thanks for your assistance. With a couple of tweaks, the findControl
    function was exactly what I needed to get at the object and its id (turns out
    I was looking for a "div" control rather than a "table" control).
    --
    dchillman


    "Phillip Williams" wrote:

    > The reason you get the error that "FpSpread1 is undefined" is that when
    > ASP.NET renders server controls it adds the namingcontainer id as a prefix to
    > the control id.
    >
    > Instead of using the document.getElementById, try something like this:
    >
    > var table = findControl("FpSpread1");
    > if (table !=null) //do all of the processing that you want
    >
    > and write a function as this:
    >
    > <script language="javascript">
    > function findControl(ControlName)
    > {
    >
    > var aTables = document.getElementsByTagName("table");
    > if (aTables)
    > { for (var i=0; i < aTables.length ; i++)
    > {
    > if (aTables.id.lastIndexOf(ControlName) == aTables.id.length -
    > ControlName.length)
    > {
    > ret =aTables;
    > }
    > }
    > }
    > return ret;
    > }
    > </script>
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "dchillman" wrote:
    >
    > > I have a user control page (ascx) that contains a third-party spreasheet
    > > control. When the user clicks the insert button on the spreadsheet control,
    > > I am trying to pre-insert values into the new row. If I put the spreadsheet
    > > control directly on as aspx page, I can do this in the window.onload
    > > function. However, when the spreadsheet control in on an ascx page, I get an
    > > error that says the control is undefined.
    > >
    > > here is the code on the html page of the ascx.
    > >
    > > <script language="javascript">
    > >
    > > function window.onload()
    > > {
    > > //debugger
    > > var i;
    > > //var spreadRef = document.getElementById(FpSread1);
    > > var table = FpSread1.all("FpSpread1_viewPort").firstChild;
    > > for(i=1;i<=spreadRef.GetRowCount();i++)
    > > {
    > > if(table.rows.FpKey=="newRow")
    > > {
    > > alert("New Row");
    > > FpSread1.SetValue(i-1, 0, FpSread1.GetValue(i, 0));
    > > FpSread1.SetValue(i-1, 1, FpSread1.GetValue(i, 1));
    > > FpSread1.SetValue(i-1, 2, FpSread1.GetValue(i, 2));
    > > }
    > > }
    > >
    > > }
    > > </script>
    > >
    > > When the page loads, there is a yellow exclamation point that essentially
    > > states that
    > > "FpSpread1 is undefined".
    > >
    > > Is it possible to access a third party control within a user control on the
    > > clientside?
    > >
    > > Thanks for any help you can provide.
    > > --
    > > dchillman
    dchillman, Nov 2, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kieran Benton
    Replies:
    3
    Views:
    503
    Ray Cassick \(home\)
    Sep 11, 2003
  2. Billy Porter
    Replies:
    0
    Views:
    1,015
    Billy Porter
    Jun 25, 2003
  3. Mikael Engdahl

    Strange error when calling third party assembly

    Mikael Engdahl, Aug 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    362
    Mikael Engdahl
    Aug 8, 2003
  4. Cowboy \(Gregory A. Beamer\)

    Re: Use Third Party HTML Designer

    Cowboy \(Gregory A. Beamer\), Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    362
    Marty Cruise
    Nov 5, 2003
  5. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    545
    Martin Honnen
    Nov 4, 2004
Loading...

Share This Page