referring to a third-party contol in window.onload

D

dchillman

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.
 
P

Phillip Williams

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>
 
D

dchillman

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 said:
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 said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top