Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > referring to a third-party contol in window.onload

Reply
Thread Tools

referring to a third-party contol in window.onload

 
 
dchillman
Guest
Posts: n/a
 
      10-31-2005
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[i].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
 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      10-31-2005
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[i].id.lastIndexOf(ControlName) == aTables[i].id.length -
ControlName.length)
{
ret =aTables[i];
}
}
}
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[i].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

 
Reply With Quote
 
 
 
 
dchillman
Guest
Posts: n/a
 
      11-02-2005
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[i].id.lastIndexOf(ControlName) == aTables[i].id.length -
> ControlName.length)
> {
> ret =aTables[i];
> }
> }
> }
> 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[i].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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting handle on contol programatically Sosh123 ASP .Net 1 05-20-2005 02:59 PM
How to refer a contol in userControl ad ASP .Net 3 04-28-2005 01:08 PM
how to add a contol after datagrid that changes size? Dee ASP .Net 2 04-25-2005 08:34 PM
Contol Location on Webform Jeff Gaines ASP .Net 4 11-27-2004 09:10 PM
Button Contol =?Utf-8?B?TW9lSm9l?= ASP .Net 3 05-30-2004 12:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57