getElementById doesn't seem to work

T

tshad

I have an aspx window that is calling another window and I am trying to get
a couple of objects from the opening page. The problem is that I can't seem
to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and if
I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the first
objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of the
form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about 200
objects on the page. Some of the objects are being shown inside of the User
control - but "theBox" doesn't show at all. And it is one of the first
ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the length as
25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom
 
T

tshad

In FireFox, the length show 3 so doesn't work at all.

Not sure how to get this to work.

Thanks,

Tom

tshad said:
I have an aspx window that is calling another window and I am trying to get
a couple of objects from the opening page. The problem is that I can't
seem to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and
if I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the first
objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of
the form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about 200
objects on the page. Some of the objects are being shown inside of the
User control - but "theBox" doesn't show at all. And it is one of the
first ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the length
as 25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom
 
L

Lit

View the source and find out the exact id of the element.
use the server-side element-id .clientID

<%=ServerSideControlID.ClientID%>

Lit

tshad said:
I have an aspx window that is calling another window and I am trying to get
a couple of objects from the opening page. The problem is that I can't
seem to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and
if I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the first
objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of
the form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about 200
objects on the page. Some of the objects are being shown inside of the
User control - but "theBox" doesn't show at all. And it is one of the
first ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the length
as 25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom
 
B

bruce barker

as the post below said, you need the id rendered (control.ClientId).

also the form.elements collection only contains form controls
(input,select and textarea). only form elements have a type and name
property.

also as firefox is strict, you need to specify:

document.addForm.elements

to find dom objects like a span or anchor (link), you want to walk
childNodes recursively.

-- bruce (sqlwork.com)
In FireFox, the length show 3 so doesn't work at all.

Not sure how to get this to work.

Thanks,

Tom

tshad said:
I have an aspx window that is calling another window and I am trying to get
a couple of objects from the opening page. The problem is that I can't
seem to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and
if I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the first
objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of
the form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about 200
objects on the page. Some of the objects are being shown inside of the
User control - but "theBox" doesn't show at all. And it is one of the
first ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the length
as 25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom

 
T

tshad

bruce barker said:
as the post below said, you need the id rendered (control.ClientId).

also the form.elements collection only contains form controls
(input,select and textarea). only form elements have a type and name
property.

also as firefox is strict, you need to specify:

document.addForm.elements

to find dom objects like a span or anchor (link), you want to walk
childNodes recursively.

You're right on the span. I hadn't realized I was using a Label (when I
changed it to a textbox it worked fine). But I do need to get the
Label/Span and my walking the nodes is not working correctly.

I am doing the following:

alert("length = " + document.addForm.length);
for (var i = 0;i< document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}

But this doesn't seem to find the span tag (which has an id). I assume I am
not following the whole path.

How would I change this so I would find the span tag?

Thanks,

Tom
-- bruce (sqlwork.com)
In FireFox, the length show 3 so doesn't work at all.

Not sure how to get this to work.

Thanks,

Tom

tshad said:
I have an aspx window that is calling another window and I am trying to
get a couple of objects from the opening page. The problem is that I
can't seem to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and
if I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the
first objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of
the form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about
200 objects on the page. Some of the objects are being shown inside of
the User control - but "theBox" doesn't show at all. And it is one of
the first ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink
System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the
length as 25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom

 
T

tshad

Lit said:
View the source and find out the exact id of the element.
use the server-side element-id .clientID

<%=ServerSideControlID.ClientID%>

Where would I put this and how would I use it?

Thanks,

Tom
Lit

tshad said:
I have an aspx window that is calling another window and I am trying to
get a couple of objects from the opening page. The problem is that I
can't seem to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and
if I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the first
objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of
the form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about
200 objects on the page. Some of the objects are being shown inside of
the User control - but "theBox" doesn't show at all. And it is one of
the first ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the length
as 25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom

 
B

bruce barker

as i said, you need to use the childNodes, and a span does not have a
type or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}

or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');

-- bruce (sqlwork.com)
bruce barker said:
as the post below said, you need the id rendered (control.ClientId).

also the form.elements collection only contains form controls
(input,select and textarea). only form elements have a type and name
property.

also as firefox is strict, you need to specify:

document.addForm.elements

to find dom objects like a span or anchor (link), you want to walk
childNodes recursively.

You're right on the span. I hadn't realized I was using a Label (when I
changed it to a textbox it worked fine). But I do need to get the
Label/Span and my walking the nodes is not working correctly.

I am doing the following:

alert("length = " + document.addForm.length);
for (var i = 0;i< document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}

But this doesn't seem to find the span tag (which has an id). I assume I am
not following the whole path.

How would I change this so I would find the span tag?

Thanks,

Tom
-- bruce (sqlwork.com)
In FireFox, the length show 3 so doesn't work at all.

Not sure how to get this to work.

Thanks,

Tom

I have an aspx window that is calling another window and I am trying to
get a couple of objects from the opening page. The problem is that I
can't seem to get anything inside of my form.

I have the following in my opener page:

<body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" runat="server">
<form id="addForm" runat="server">
<asp:label id="theBox" text = "a test" runat="server"/>
<asp:placeHolder ID="thePlaceHolder" runat="server"/>
</form>
</body>

The "thePlaceHolder" object is where I put my User object.

I am trying to get to some of the objects inside of this user object and
if I walk the Dom I can see some (but not all the objects).

I can't even seem to get to the "theBox" object which is one of the
first objects in the Dom. I tried to get the object like this:

function entry()
{
alert("On Entry");
var theObject = window.opener.document.getElementById('theBox');
alert("After Entry theObject = " + theObject);

alert("length = " + window.opener.document.addForm.length);

for (var i = 0;i< window.opener.document.addForm.length;i++)
{
alert("inside for loop i = " + i);
var e = window.opener.document.addForm.elements;
alert("e.type = " + e.type);
alert("e.name = " + e.name);
}
}

theObject ends up being null. If I move the "theBox" object outside of
the form, it seems to find it fine.

When I walk the Dom, the length is about 25 and I know there are about
200 objects on the page. Some of the objects are being shown inside of
the User control - but "theBox" doesn't show at all. And it is one of
the first ones.

The trace shows the first part of the objects as:

__PAGE ASP.ResumeSubmittalForm_aspx
_ctl1 System.Web.UI.LiteralControl
_ctl2 System.Web.UI.LiteralControl
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl
_ctl3 System.Web.UI.LiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl4 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl5 System.Web.UI.LiteralControl
theBox System.Web.UI.WebControls.Label
_ctl6 System.Web.UI.LiteralControl
thePlaceHolder System.Web.UI.WebControls.PlaceHolder
_ctl0 ASP.mainPage_ascx
_ctl0:_ctl2 System.Web.UI.ResourceBasedLiteralControl
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl3 System.Web.UI.LiteralControl
_ctl0:MyInformationLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl4 System.Web.UI.LiteralControl
_ctl0:ResumeLink System.Web.UI.WebControls.HyperLink
_ctl0:_ctl5 System.Web.UI.LiteralControl
_ctl0:CoverLetterLink
System.Web.UI.WebControls.HyperLink
_ctl0:_ctl6 System.Web.UI.LiteralControl
_ctl0:passportLink
System.Web.UI.WebControls.HyperLink

The Forms collection shows as:

__EVENTTARGET _ctl0:_ctl1:previewLink
__EVENTARGUMENT
__VIEWSTATE dDwzNj
_ctl0:_ctl1:resumes 0
ctl0__ctl1_ResumeText
ctl0__ctl1_CoverLetter
_ctl0:_ctl1:GenderList
_ctl0:_ctl1:EthnicityList
_ctl0:_ctl1:VeteranStatus
_sk_scrollkeepervalue 0!0

Where is the "theBox" control and when walking the Dom it show the
length as 25.

What is going on?????

Is this a problem with asp.net 1.1????

Thanks,

Tom

 
M

Mark Rae [MVP]

Where would I put this and how would I use it?

Wherever you need to use methods like getElementById which find a control by
its ID...

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');
 
T

tshad

Mark Rae said:
Wherever you need to use methods like getElementById which find a control
by its ID...

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');

I have seen this before but am not sure what it does.

What is the difference between:

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');

and

var myTextBox = getElementById('MyTextBox');

Why would the first one get me a span element and the 2nd one not?

Thanks,

Tom
 
L

Lit

tshad,

When you give a server control an ID the client ID is not the same.
ASP.NET adds more to it to be unique.

After you render your web page in the Browser go to the ViewSource and look
for yourself.

The ID is much longer in length because the ASP.NET added more to it to
make it unique. This is due to: what if you have the same user control
multiple times on the same web page.

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');
ASP.NET rendering engine Does the Substitution for what the Client ID is you
don't know it.

var myTextBox = getElementById('MyTextBox');
This is Fixed, you only have the Server Side ID and not the Client Side ID.

Again View the Source in the browser to see how the Server ID is NOT the
same as the Client ID for the Same TextBox or Label or what ever.

Lit


tshad said:
Mark Rae said:
Wherever you need to use methods like getElementById which find a control
by its ID...

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');

I have seen this before but am not sure what it does.

What is the difference between:

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');

and

var myTextBox = getElementById('MyTextBox');

Why would the first one get me a span element and the 2nd one not?

Thanks,

Tom
 
M

Mark Rae [MVP]

What is the difference between:

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');

and

var myTextBox = getElementById('MyTextBox');

The first makes sure that the correct ID is being used. ASP.NET will munge
the IDs of client controls when they are contained within MasterPages or
other UserControls...

Basically, always use the first one and never the second...
Why would the first one get me a span element and the 2nd one not?

What do you mean by "get me a span element"...? What type of control is
being referenced...?
 
T

tshad

"bruce barker" <[email protected]> wrote in message
as i said, you need to use the childNodes, and a span does not have a type
or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}

or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');


I tried that but it gives me an error:

*******************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText' is
not declared.

Source Error:

Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
*******************************************************

Here is the code:

var fromResumeText =
window.opener.document.getElementById('ctl0__ctl1_ResumeText');
var fromCoverLetter =
window.opener.document.getElementById('ctl0__ctl1_CoverLetter');
// var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

I am looking for 2 objects on my opener page and 2 from my current page. I
can find all the objects except the 'ctl0_ResumeDisplay_objResumeText' which
is the only object that is an asp:Label.

This code worked fine except that it didn't find Label objects - it found
the other 3.

This error happened when I added the <%=...%> format.

The interesting thing is that I get the error even when I comment out the
new line and the error is on the commented out line????

***************************************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText' is
not declared.

Source Error:

Line 47: var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: // var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
******************************************************************************************The error is on line 48.How can that be??? It is commented out.The trace for this page is:_ctl0:ResumeDisplay:eek:bjResumeText System.Web.UI.WebControls.Label_ctl0:ResumeDisplay:_ctl51 System.Web.UI.LiteralControl_ctl0:ResumeDisplay:eek:bjCoverLetterTextBox FreeTextBoxControls.FreeTextBox_ctl0:ResumeDisplay:_ctl30 System.Web.UI.LiteralControlIt says that 'ctl0_ResumeDisplay_objResumeText' doesn't exist. I don't getthe error message if I don't use the <%=...%> format. It doesn't find it,but I don't get an error message just a null.Thanks,Tom>> -- bruce (sqlwork.com)>> tshad wrote:>> "bruce barker" <[email protected]> wrote in messagenews:%[email protected]...>>> as the post below said, you need the id rendered (control.ClientId).>>>>>> also the form.elements collection only contains form controls(input,select and textarea). only form elements have a type and nameproperty.>>>>>> also as firefox is strict, you need to specify:>>>>>> document.addForm.elements>>>>>> to find dom objects like a span or anchor (link), you want to walkchildNodes recursively.>>>>>>> You're right on the span. I hadn't realized I was using a Label (when Ichanged it to a textbox it worked fine). But I do need to get theLabel/Span and my walking the nodes is not working correctly.>>>> I am doing the following:>>>> alert("length = " + document.addForm.length);>> for (var i = 0;i< document.addForm.length;i++)>> {>> alert("inside for loop i = " + i);>> var e = document.addForm.elements;>> alert("e.type = " + e.type);>> alert("e.name = " + e.name);>> }>>>> But this doesn't seem to find the span tag (which has an id). I assume Iam not following the whole path.>>>> How would I change this so I would find the span tag?>>>> Thanks,>>>> Tom>>>>> -- bruce (sqlwork.com)>>>>>> tshad wrote:>>>> In FireFox, the length show 3 so doesn't work at all.>>>>>>>> Not sure how to get this to work.>>>>>>>> Thanks,>>>>>>>> Tom>>>>>>>> "tshad" <[email protected]> wrote in messagenews:[email protected]...>>>>> I have an aspx window that is calling another window and I am tryingto get a couple of objects from the opening page. The problem is that Ican't seem to get anything inside of my form.>>>>>>>>>> I have the following in my opener page:>>>>>>>>>> <body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"marginheight="0" runat="server">>>>>> <form id="addForm" runat="server">>>>>> <asp:label id="theBox" text = "a test" runat="server"/>>>>>> <asp:placeHolder ID="thePlaceHolder" runat="server"/>>>>>> </form>>>>>> </body>>>>>>>>>>> The "thePlaceHolder" object is where I put my User object.>>>>>>>>>> I am trying to get to some of the objects inside of this user objectand if I walk the Dom I can see some (but not all the objects).>>>>>>>>>> I can't even seem to get to the "theBox" object which is one of thefirst objects in the Dom. I tried to get the object like this:>>>>>>>>>> function entry()>>>>> {>>>>> alert("On Entry");>>>>> var theObject = window.opener.document.getElementById('theBox');>>>>> alert("After Entry theObject = " + theObject);>>>>>>>>>> alert("length = " + window.opener.document.addForm.length);>>>>>>>>>> for (var i = 0;i< window.opener.document.addForm.length;i++)>>>>> {>>>>> alert("inside for loop i = " + i);>>>>> var e = window.opener.document.addForm.elements;>>>>> alert("e.type = " + e.type);>>>>> alert("e.name = " + e.name);>>>>> }>>>>> }>>>>>>>>>> theObject ends up being null. If I move the "theBox" object outsideof the form, it seems to find it fine.>>>>>>>>>> When I walk the Dom, the length is about 25 and I know there are about200 objects on the page. Some of the objects are being shown inside of theUser control - but "theBox" doesn't show at all. And it is one of the firstones.>>>>>>>>>> The trace shows the first part of the objects as:>>>>>>>>>> __PAGE ASP.ResumeSubmittalForm_aspx>>>>> _ctl1 System.Web.UI.LiteralControl>>>>> _ctl2 System.Web.UI.LiteralControl>>>>> MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl3 System.Web.UI.LiteralControl>>>>> myBody System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl4 System.Web.UI.LiteralControl>>>>> addForm System.Web.UI.HtmlControls.HtmlForm>>>>> _ctl5 System.Web.UI.LiteralControl>>>>> theBox System.Web.UI.WebControls.Label>>>>> _ctl6 System.Web.UI.LiteralControl>>>>> thePlaceHolder System.Web.UI.WebControls.PlaceHolder>>>>> _ctl0 ASP.mainPage_ascx>>>>> _ctl0:_ctl2System.Web.UI.ResourceBasedLiteralControl>>>>> _ctl0:HomeLink System.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl3 System.Web.UI.LiteralControl>>>>> _ctl0:MyInformationLinkSystem.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl4 System.Web.UI.LiteralControl>>>>> _ctl0:ResumeLinkSystem.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl5 System.Web.UI.LiteralControl>>>>> _ctl0:CoverLetterLinkSystem.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl6 System.Web.UI.LiteralControl>>>>> _ctl0:passportLinkSystem.Web.UI.WebControls.HyperLink>>>>>>>>>> The Forms collection shows as:>>>>>>>>>> __EVENTTARGET _ctl0:_ctl1:previewLink>>>>> __EVENTARGUMENT>>>>> __VIEWSTATE dDwzNj>>>>> _ctl0:_ctl1:resumes 0>>>>> ctl0__ctl1_ResumeText>>>>> ctl0__ctl1_CoverLetter>>>>> _ctl0:_ctl1:GenderList>>>>> _ctl0:_ctl1:EthnicityList>>>>> _ctl0:_ctl1:VeteranStatus>>>>> _sk_scrollkeepervalue 0!0>>>>>>>>>> Where is the "theBox" control and when walking the Dom it show thelength as 25.>>>>>>>>>> What is going on?????>>>>>>>>>> Is this a problem with asp.net 1.1????>>>>>>>>>> Thanks,>>>>>>>>>> Tom>>>>>>>
 
T

tshad

tshad said:
bruce barker said:
as i said, you need to use the childNodes, and a span does not have a
type or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}


I tried the following but it quit in the for loop. I added a couple of
alerts to see what caused it to fail:
****************************************
var nodes = document.forms[0].childNodes;

alert("nodes = " + nodes + " nodes.length = " + nodes.length);

for (var i=0; i < nodes.length; ++i)
{
alert("Inside for loop - i = " + i);
alert("tag: = " + node.tagName);
alert("id: = " + nodes.id);
alert("tag: " + node.tagName + " id: " + nodes.id);
}

alert("length = " + document.addForm.length);
*****************************************

I get "nodes = [object]" and "nodes.length = 24". I also get one "inside
for loop - i = 0" message but then I don't get anymore messages. So the
node.tagName gives me an error.

Thanks,

Tom
or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');

I tried that but it gives me an error:

*******************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
*******************************************************

Here is the code:

var fromResumeText =
window.opener.document.getElementById('ctl0__ctl1_ResumeText');
var fromCoverLetter =
window.opener.document.getElementById('ctl0__ctl1_CoverLetter');
// var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

I am looking for 2 objects on my opener page and 2 from my current page.
I can find all the objects except the 'ctl0_ResumeDisplay_objResumeText'
which is the only object that is an asp:Label.

This code worked fine except that it didn't find Label objects - it found
the other 3.

This error happened when I added the <%=...%> format.

The interesting thing is that I get the error even when I comment out the
new line and the error is on the commented out line????

***************************************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: // var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
******************************************************************************************The
error is on line 48.How can that be??? It is commented out.The trace for
this page is:_ctl0:ResumeDisplay:eek:bjResumeText
System.Web.UI.WebControls.Label_ctl0:ResumeDisplay:_ctl51
System.Web.UI.LiteralControl_ctl0:ResumeDisplay:eek:bjCoverLetterTextBox
FreeTextBoxControls.FreeTextBox_ctl0:ResumeDisplay:_ctl30
System.Web.UI.LiteralControlIt says that
'ctl0_ResumeDisplay_objResumeText' doesn't exist. I don't getthe error
message if I don't use the <%=...%> format. It doesn't find it,but I
don't get an error message just a null.Thanks,Tom>> -- bruce
messageas the post
below said, you need the id rendered (control.ClientId).>>>>>> also the
form.elements collection only contains form controls(input,select and
textarea). only form elements have a type and nameproperty.>>>>>> also as
firefox is strict, you need to specify:>>>>>>
document.addForm.elements>>>>>> to find dom objects like a span or anchor
(link), you want to walkchildNodes recursively.>>>>>>> You're right on the
span. I hadn't realized I was using a Label (when Ichanged it to a
textbox it worked fine). But I do need to get theLabel/Span and my
walking the nodes is not working correctly.>>>> I am doing the
following:>>>> alert("length = " + document.addForm.length);>> for (var
i = 0;i< document.addForm.length;i++)>> {>> alert("inside for loop i =
" + i);>> var e = document.addForm.elements;>> alert("e.type = " +
e.type);>> alert("e.name = " + e.name);>> }>>>> But this doesn't seem
to find the span tag (which has an id). I assume Iam not following the
whole path.>>>> How would I change this so I would find the span tag?>>>>
Thanks,>>>> Tom>>>>> -- bruce (sqlwork.com)>>>>>> tshad wrote:>>>> In
FireFox, the length show 3 so doesn't work at all.>>>>>>>> Not sure how to
get this to work.>>>>>>>> Thanks,>>>>>>>> Tom>>>>>>>> "tshad" <[email protected]>
wrote in messageI have
an aspx window that is calling another window and I am tryingto get a
couple of objects from the opening page. The problem is that Ican't seem
to get anything inside of my form.>>>>>>>>>> I have the following in my
opener page:>>>>>>>>>> <body id="myBody" leftmargin="0" topmargin="0"
marginwidth="0"marginheight="0" runat="server">>>>>> <form id="addForm"
runat="server">>>>>> <asp:label id="theBox" text = "a test"
runat="server"/>>>>>> <asp:placeHolder ID="thePlaceHolder"
runat="server"/>>>>>> </form>>>>>> </body>>>>>>>>>>> The "thePlaceHolder"
object is where I put my User object.>>>>>>>>>> I am trying to get to some
of the objects inside of this user objectand if I walk the Dom I can see
some (but not all the objects).>>>>>>>>>> I can't even seem to get to the
"theBox" object which is one of thefirst objects in the Dom. I tried to
get the object like this:>>>>>>>>>> function entry()>>>>> {>>>>> alert("On
Entry");>>>>> var theObject =
window.opener.document.getElementById('theBox');>>>>> alert("After Entry
theObject = " + theObject);>>>>>>>>>> alert("length = " +
window.opener.document.addForm.length);>>>>>>>>>> for (var i = 0;i<
window.opener.document.addForm.length;i++)>>>>> {>>>>> alert("inside
for loop i = " + i);>>>>> var e =
window.opener.document.addForm.elements;>>>>> alert("e.type = " +
e.type);>>>>> alert("e.name = " + e.name);>>>>> }>>>>> }>>>>>>>>>>
theObject ends up being null. If I move the "theBox" object outsideof the
form, it seems to find it fine.>>>>>>>>>> When I walk the Dom, the length
is about 25 and I know there are about200 objects on the page. Some of
the objects are being shown inside of theUser control - but "theBox"
doesn't show at all. And it is one of the firstones.>>>>>>>>>> The trace
shows the first part of the objects as:>>>>>>>>>> __PAGE
ASP.ResumeSubmittalForm_aspx>>>>> _ctl1 System.Web.UI.LiteralControl>>>>>
_ctl2 System.Web.UI.LiteralControl>>>>> MyStyleSheet
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl3
System.Web.UI.LiteralControl>>>>> myBody
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl4
System.Web.UI.LiteralControl>>>>> addForm
System.Web.UI.HtmlControls.HtmlForm>>>>> _ctl5
System.Web.UI.LiteralControl>>>>> theBox
System.Web.UI.WebControls.Label>>>>> _ctl6
System.Web.UI.LiteralControl>>>>> thePlaceHolder
System.Web.UI.WebControls.PlaceHolder>>>>> _ctl0
ASP.mainPage_ascx>>>>>
_ctl0:_ctl2System.Web.UI.ResourceBasedLiteralControl>>>>>
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl3 System.Web.UI.LiteralControl>>>>>
_ctl0:MyInformationLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl4 System.Web.UI.LiteralControl>>>>>
_ctl0:ResumeLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl5 System.Web.UI.LiteralControl>>>>>
_ctl0:CoverLetterLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl6 System.Web.UI.LiteralControl>>>>>
_ctl0:passportLinkSystem.Web.UI.WebControls.HyperLink>>>>>>>>>> The Forms
collection shows as:>>>>>>>>>> __EVENTTARGET _ctl0:_ctl1:previewLink>>>>>
__EVENTARGUMENT>>>>> __VIEWSTATE dDwzNj>>>>> _ctl0:_ctl1:resumes 0>>>>>
ctl0__ctl1_ResumeText>>>>> ctl0__ctl1_CoverLetter>>>>>
_ctl0:_ctl1:GenderList>>>>> _ctl0:_ctl1:EthnicityList>>>>>
_ctl0:_ctl1:VeteranStatus>>>>> _sk_scrollkeepervalue 0!0>>>>>>>>>> Where
is the "theBox" control and when walking the Dom it show thelength as
25.>>>>>>>>>> What is going on?????>>>>>>>>>> Is this a problem with
asp.net 1.1????>>>>>>>>>> Thanks,>>>>>>>>>> Tom>>>>>>>
 
T

tshad

Lit said:
tshad,

When you give a server control an ID the client ID is not the same.
ASP.NET adds more to it to be unique.

After you render your web page in the Browser go to the ViewSource and
look for yourself.

The ID is much longer in length because the ASP.NET added more to it to
make it unique. This is due to: what if you have the same user control
multiple times on the same web page.

var myTextBox = getElementById('<%=MyTextBox.ClientID%>');
ASP.NET rendering engine Does the Substitution for what the Client ID is
you don't know it.

var myTextBox = getElementById('MyTextBox');
This is Fixed, you only have the Server Side ID and not the Client Side
ID.

Again View the Source in the browser to see how the Server ID is NOT the
same as the Client ID for the Same TextBox or Label or what ever.

Ok,

Here are 2 object. One asp:Textbox and one asp:Label. The TextBox is
MyFile and the Label is UploadErrorMessage.

<input name="_ctl0:_ctl1:MyFile" id="_ctl0__ctl1_MyFile" type="File"
style="width:200px" />
<span id="_ctl0__ctl1_UploadErrorMessage" style="color:Red;"></span>

The span has no "name" but both have ids. Is the "id" the ClientID?

Thanks,

Tom
 
T

tshad

Mark Rae said:
The first makes sure that the correct ID is being used. ASP.NET will munge
the IDs of client controls when they are contained within MasterPages or
other UserControls...

Basically, always use the first one and never the second...


What do you mean by "get me a span element"...? What type of control is
being referenced...?

Well, the one I am having problems with is the span element which is the
asp:Label. In my view source I see it as:

<input name="_ctl0:_ctl1:MyFile" id="_ctl0__ctl1_MyFile" type="File"
style="width:200px" />
<span id="_ctl0__ctl1_UploadErrorMessage" style="color:Red;"></span>

The UploadErrorMessage is the asp:label. I assume the "id" is the what I am
trying to get with the <%=...%> format.

Thanks,

Tom
 
L

Lit

tshad,

This is wrong.
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');

it looks like you are getting the ClientId on the clientId

<%=The_ID_Of_Your_Server_Control.ClientId%>

What is the ID of your Label

if the ServerSide ID of your Label is MyLabel123 then use
<%=MyLabel123.ClientID%> -- verify syntax

Make sure Label is runat="server"

Lit




tshad said:
bruce barker said:
as i said, you need to use the childNodes, and a span does not have a
type or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}

or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');


I tried that but it gives me an error:

*******************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
*******************************************************

Here is the code:

var fromResumeText =
window.opener.document.getElementById('ctl0__ctl1_ResumeText');
var fromCoverLetter =
window.opener.document.getElementById('ctl0__ctl1_CoverLetter');
// var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

I am looking for 2 objects on my opener page and 2 from my current page.
I can find all the objects except the 'ctl0_ResumeDisplay_objResumeText'
which is the only object that is an asp:Label.

This code worked fine except that it didn't find Label objects - it found
the other 3.

This error happened when I added the <%=...%> format.

The interesting thing is that I get the error even when I comment out the
new line and the error is on the commented out line????

***************************************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: // var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
******************************************************************************************The
error is on line 48.How can that be??? It is commented out.The trace for
this page is:_ctl0:ResumeDisplay:eek:bjResumeText
System.Web.UI.WebControls.Label_ctl0:ResumeDisplay:_ctl51
System.Web.UI.LiteralControl_ctl0:ResumeDisplay:eek:bjCoverLetterTextBox
FreeTextBoxControls.FreeTextBox_ctl0:ResumeDisplay:_ctl30
System.Web.UI.LiteralControlIt says that
'ctl0_ResumeDisplay_objResumeText' doesn't exist. I don't getthe error
message if I don't use the <%=...%> format. It doesn't find it,but I
don't get an error message just a null.Thanks,Tom>> -- bruce
messageas the post
below said, you need the id rendered (control.ClientId).>>>>>> also the
form.elements collection only contains form controls(input,select and
textarea). only form elements have a type and nameproperty.>>>>>> also as
firefox is strict, you need to specify:>>>>>>
document.addForm.elements>>>>>> to find dom objects like a span or anchor
(link), you want to walkchildNodes recursively.>>>>>>> You're right on the
span. I hadn't realized I was using a Label (when Ichanged it to a
textbox it worked fine). But I do need to get theLabel/Span and my
walking the nodes is not working correctly.>>>> I am doing the
following:>>>> alert("length = " + document.addForm.length);>> for (var
i = 0;i< document.addForm.length;i++)>> {>> alert("inside for loop i =
" + i);>> var e = document.addForm.elements;>> alert("e.type = " +
e.type);>> alert("e.name = " + e.name);>> }>>>> But this doesn't seem
to find the span tag (which has an id). I assume Iam not following the
whole path.>>>> How would I change this so I would find the span tag?>>>>
Thanks,>>>> Tom>>>>> -- bruce (sqlwork.com)>>>>>> tshad wrote:>>>> In
FireFox, the length show 3 so doesn't work at all.>>>>>>>> Not sure how to
get this to work.>>>>>>>> Thanks,>>>>>>>> Tom>>>>>>>> "tshad" <[email protected]>
wrote in messageI have
an aspx window that is calling another window and I am tryingto get a
couple of objects from the opening page. The problem is that Ican't seem
to get anything inside of my form.>>>>>>>>>> I have the following in my
opener page:>>>>>>>>>> <body id="myBody" leftmargin="0" topmargin="0"
marginwidth="0"marginheight="0" runat="server">>>>>> <form id="addForm"
runat="server">>>>>> <asp:label id="theBox" text = "a test"
runat="server"/>>>>>> <asp:placeHolder ID="thePlaceHolder"
runat="server"/>>>>>> </form>>>>>> </body>>>>>>>>>>> The "thePlaceHolder"
object is where I put my User object.>>>>>>>>>> I am trying to get to some
of the objects inside of this user objectand if I walk the Dom I can see
some (but not all the objects).>>>>>>>>>> I can't even seem to get to the
"theBox" object which is one of thefirst objects in the Dom. I tried to
get the object like this:>>>>>>>>>> function entry()>>>>> {>>>>> alert("On
Entry");>>>>> var theObject =
window.opener.document.getElementById('theBox');>>>>> alert("After Entry
theObject = " + theObject);>>>>>>>>>> alert("length = " +
window.opener.document.addForm.length);>>>>>>>>>> for (var i = 0;i<
window.opener.document.addForm.length;i++)>>>>> {>>>>> alert("inside
for loop i = " + i);>>>>> var e =
window.opener.document.addForm.elements;>>>>> alert("e.type = " +
e.type);>>>>> alert("e.name = " + e.name);>>>>> }>>>>> }>>>>>>>>>>
theObject ends up being null. If I move the "theBox" object outsideof the
form, it seems to find it fine.>>>>>>>>>> When I walk the Dom, the length
is about 25 and I know there are about200 objects on the page. Some of
the objects are being shown inside of theUser control - but "theBox"
doesn't show at all. And it is one of the firstones.>>>>>>>>>> The trace
shows the first part of the objects as:>>>>>>>>>> __PAGE
ASP.ResumeSubmittalForm_aspx>>>>> _ctl1 System.Web.UI.LiteralControl>>>>>
_ctl2 System.Web.UI.LiteralControl>>>>> MyStyleSheet
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl3
System.Web.UI.LiteralControl>>>>> myBody
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl4
System.Web.UI.LiteralControl>>>>> addForm
System.Web.UI.HtmlControls.HtmlForm>>>>> _ctl5
System.Web.UI.LiteralControl>>>>> theBox
System.Web.UI.WebControls.Label>>>>> _ctl6
System.Web.UI.LiteralControl>>>>> thePlaceHolder
System.Web.UI.WebControls.PlaceHolder>>>>> _ctl0
ASP.mainPage_ascx>>>>>
_ctl0:_ctl2System.Web.UI.ResourceBasedLiteralControl>>>>>
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl3 System.Web.UI.LiteralControl>>>>>
_ctl0:MyInformationLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl4 System.Web.UI.LiteralControl>>>>>
_ctl0:ResumeLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl5 System.Web.UI.LiteralControl>>>>>
_ctl0:CoverLetterLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl6 System.Web.UI.LiteralControl>>>>>
_ctl0:passportLinkSystem.Web.UI.WebControls.HyperLink>>>>>>>>>> The Forms
collection shows as:>>>>>>>>>> __EVENTTARGET _ctl0:_ctl1:previewLink>>>>>
__EVENTARGUMENT>>>>> __VIEWSTATE dDwzNj>>>>> _ctl0:_ctl1:resumes 0>>>>>
ctl0__ctl1_ResumeText>>>>> ctl0__ctl1_CoverLetter>>>>>
_ctl0:_ctl1:GenderList>>>>> _ctl0:_ctl1:EthnicityList>>>>>
_ctl0:_ctl1:VeteranStatus>>>>> _sk_scrollkeepervalue 0!0>>>>>>>>>> Where
is the "theBox" control and when walking the Dom it show thelength as
25.>>>>>>>>>> What is going on?????>>>>>>>>>> Is this a problem with
asp.net 1.1????>>>>>>>>>> Thanks,>>>>>>>>>> Tom>>>>>>>
 
M

Mark Rae [MVP]

<span id="_ctl0__ctl1_UploadErrorMessage" style="color:Red;"></span>

The UploadErrorMessage is the asp:label. I assume the "id" is the what I
am trying to get with the <%=...%> format.

Yes.
 
T

tshad

I changed the ID to be what was in the View Source to see if that was the
problem, but got the same error:

Compiler Error Message: BC30451: Name '_ctl0_ResumeDisplay_objResumeText' is
not declared.

Source Error:

Line 46: alert("After Entry fromCoverLetter = " + fromCoverLetter);
Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.forms[0].getElementById('<%=_ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 49: alert("After Entry toResumeText = " + toResumeText);
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

The error is on line 48.

The lines in the ViewSource is:

<tr bgcolor="#F3F3F3">
<td><p style="margin-left:10px"><span
id="_ctl0_ResumeDisplay_objResumeText"></span>
<br> <br>
</td>
</tr>

As you can see, the id =_ctl0_ResumeDisplay_objResumeText but the comiler
says it doesn't exist.

Thanks,

Tom

tshad said:
bruce barker said:
as i said, you need to use the childNodes, and a span does not have a
type or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}

or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');


I tried that but it gives me an error:

*******************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
*******************************************************

Here is the code:

var fromResumeText =
window.opener.document.getElementById('ctl0__ctl1_ResumeText');
var fromCoverLetter =
window.opener.document.getElementById('ctl0__ctl1_CoverLetter');
// var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

I am looking for 2 objects on my opener page and 2 from my current page.
I can find all the objects except the 'ctl0_ResumeDisplay_objResumeText'
which is the only object that is an asp:Label.

This code worked fine except that it didn't find Label objects - it found
the other 3.

This error happened when I added the <%=...%> format.

The interesting thing is that I get the error even when I comment out the
new line and the error is on the commented out line????

***************************************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: // var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
******************************************************************************************The
error is on line 48.How can that be??? It is commented out.The trace for
this page is:_ctl0:ResumeDisplay:eek:bjResumeText
System.Web.UI.WebControls.Label_ctl0:ResumeDisplay:_ctl51
System.Web.UI.LiteralControl_ctl0:ResumeDisplay:eek:bjCoverLetterTextBox
FreeTextBoxControls.FreeTextBox_ctl0:ResumeDisplay:_ctl30
System.Web.UI.LiteralControlIt says that
'ctl0_ResumeDisplay_objResumeText' doesn't exist. I don't getthe error
message if I don't use the <%=...%> format. It doesn't find it,but I
don't get an error message just a null.Thanks,Tom>> -- bruce
messageas the post
below said, you need the id rendered (control.ClientId).>>>>>> also the
form.elements collection only contains form controls(input,select and
textarea). only form elements have a type and nameproperty.>>>>>> also as
firefox is strict, you need to specify:>>>>>>
document.addForm.elements>>>>>> to find dom objects like a span or anchor
(link), you want to walkchildNodes recursively.>>>>>>> You're right on the
span. I hadn't realized I was using a Label (when Ichanged it to a
textbox it worked fine). But I do need to get theLabel/Span and my
walking the nodes is not working correctly.>>>> I am doing the
following:>>>> alert("length = " + document.addForm.length);>> for (var
i = 0;i< document.addForm.length;i++)>> {>> alert("inside for loop i =
" + i);>> var e = document.addForm.elements;>> alert("e.type = " +
e.type);>> alert("e.name = " + e.name);>> }>>>> But this doesn't seem
to find the span tag (which has an id). I assume Iam not following the
whole path.>>>> How would I change this so I would find the span tag?>>>>
Thanks,>>>> Tom>>>>> -- bruce (sqlwork.com)>>>>>> tshad wrote:>>>> In
FireFox, the length show 3 so doesn't work at all.>>>>>>>> Not sure how to
get this to work.>>>>>>>> Thanks,>>>>>>>> Tom>>>>>>>> "tshad" <[email protected]>
wrote in messageI have
an aspx window that is calling another window and I am tryingto get a
couple of objects from the opening page. The problem is that Ican't seem
to get anything inside of my form.>>>>>>>>>> I have the following in my
opener page:>>>>>>>>>> <body id="myBody" leftmargin="0" topmargin="0"
marginwidth="0"marginheight="0" runat="server">>>>>> <form id="addForm"
runat="server">>>>>> <asp:label id="theBox" text = "a test"
runat="server"/>>>>>> <asp:placeHolder ID="thePlaceHolder"
runat="server"/>>>>>> </form>>>>>> </body>>>>>>>>>>> The "thePlaceHolder"
object is where I put my User object.>>>>>>>>>> I am trying to get to some
of the objects inside of this user objectand if I walk the Dom I can see
some (but not all the objects).>>>>>>>>>> I can't even seem to get to the
"theBox" object which is one of thefirst objects in the Dom. I tried to
get the object like this:>>>>>>>>>> function entry()>>>>> {>>>>> alert("On
Entry");>>>>> var theObject =
window.opener.document.getElementById('theBox');>>>>> alert("After Entry
theObject = " + theObject);>>>>>>>>>> alert("length = " +
window.opener.document.addForm.length);>>>>>>>>>> for (var i = 0;i<
window.opener.document.addForm.length;i++)>>>>> {>>>>> alert("inside
for loop i = " + i);>>>>> var e =
window.opener.document.addForm.elements;>>>>> alert("e.type = " +
e.type);>>>>> alert("e.name = " + e.name);>>>>> }>>>>> }>>>>>>>>>>
theObject ends up being null. If I move the "theBox" object outsideof the
form, it seems to find it fine.>>>>>>>>>> When I walk the Dom, the length
is about 25 and I know there are about200 objects on the page. Some of
the objects are being shown inside of theUser control - but "theBox"
doesn't show at all. And it is one of the firstones.>>>>>>>>>> The trace
shows the first part of the objects as:>>>>>>>>>> __PAGE
ASP.ResumeSubmittalForm_aspx>>>>> _ctl1 System.Web.UI.LiteralControl>>>>>
_ctl2 System.Web.UI.LiteralControl>>>>> MyStyleSheet
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl3
System.Web.UI.LiteralControl>>>>> myBody
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl4
System.Web.UI.LiteralControl>>>>> addForm
System.Web.UI.HtmlControls.HtmlForm>>>>> _ctl5
System.Web.UI.LiteralControl>>>>> theBox
System.Web.UI.WebControls.Label>>>>> _ctl6
System.Web.UI.LiteralControl>>>>> thePlaceHolder
System.Web.UI.WebControls.PlaceHolder>>>>> _ctl0
ASP.mainPage_ascx>>>>>
_ctl0:_ctl2System.Web.UI.ResourceBasedLiteralControl>>>>>
_ctl0:HomeLink System.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl3 System.Web.UI.LiteralControl>>>>>
_ctl0:MyInformationLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl4 System.Web.UI.LiteralControl>>>>>
_ctl0:ResumeLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl5 System.Web.UI.LiteralControl>>>>>
_ctl0:CoverLetterLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl6 System.Web.UI.LiteralControl>>>>>
_ctl0:passportLinkSystem.Web.UI.WebControls.HyperLink>>>>>>>>>> The Forms
collection shows as:>>>>>>>>>> __EVENTTARGET _ctl0:_ctl1:previewLink>>>>>
__EVENTARGUMENT>>>>> __VIEWSTATE dDwzNj>>>>> _ctl0:_ctl1:resumes 0>>>>>
ctl0__ctl1_ResumeText>>>>> ctl0__ctl1_CoverLetter>>>>>
_ctl0:_ctl1:GenderList>>>>> _ctl0:_ctl1:EthnicityList>>>>>
_ctl0:_ctl1:VeteranStatus>>>>> _sk_scrollkeepervalue 0!0>>>>>>>>>> Where
is the "theBox" control and when walking the Dom it show thelength as
25.>>>>>>>>>> What is going on?????>>>>>>>>>> Is this a problem with
asp.net 1.1????>>>>>>>>>> Thanks,>>>>>>>>>> Tom>>>>>>>
 
T

tshad

Lit said:
tshad,

This is wrong.
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');

it looks like you are getting the ClientId on the clientId

<%=The_ID_Of_Your_Server_Control.ClientId%>

What is the ID of your Label

The asp.net line is:

<asp:Label ID="objResumeText" runat="server"/>

in the View Source it is:

<span id="_ctl0_ResumeDisplay_objResumeText"></span>

Could the error be because the objResumeText is in a User control
(ResumeDisplay)?

Thanks,

Tom
if the ServerSide ID of your Label is MyLabel123 then use
<%=MyLabel123.ClientID%> -- verify syntax

Make sure Label is runat="server"

Lit




tshad said:
bruce barker said:
as i said, you need to use the childNodes, and a span does not have a
type or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}

or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');


I tried that but it gives me an error:

*******************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
*******************************************************

Here is the code:

var fromResumeText =
window.opener.document.getElementById('ctl0__ctl1_ResumeText');
var fromCoverLetter =
window.opener.document.getElementById('ctl0__ctl1_CoverLetter');
// var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

I am looking for 2 objects on my opener page and 2 from my current page.
I can find all the objects except the 'ctl0_ResumeDisplay_objResumeText'
which is the only object that is an asp:Label.

This code worked fine except that it didn't find Label objects - it found
the other 3.

This error happened when I added the <%=...%> format.

The interesting thing is that I get the error even when I comment out the
new line and the error is on the commented out line????

***************************************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: // var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
******************************************************************************************The
error is on line 48.How can that be??? It is commented out.The trace for
this page is:_ctl0:ResumeDisplay:eek:bjResumeText
System.Web.UI.WebControls.Label_ctl0:ResumeDisplay:_ctl51
System.Web.UI.LiteralControl_ctl0:ResumeDisplay:eek:bjCoverLetterTextBox
FreeTextBoxControls.FreeTextBox_ctl0:ResumeDisplay:_ctl30
System.Web.UI.LiteralControlIt says that
'ctl0_ResumeDisplay_objResumeText' doesn't exist. I don't getthe error
message if I don't use the <%=...%> format. It doesn't find it,but I
don't get an error message just a null.Thanks,Tom>> -- bruce
in messageas the post
below said, you need the id rendered (control.ClientId).>>>>>> also the
form.elements collection only contains form controls(input,select and
textarea). only form elements have a type and nameproperty.>>>>>> also as
firefox is strict, you need to specify:>>>>>>
document.addForm.elements>>>>>> to find dom objects like a span or anchor
(link), you want to walkchildNodes recursively.>>>>>>> You're right on
the span. I hadn't realized I was using a Label (when Ichanged it to a
textbox it worked fine). But I do need to get theLabel/Span and my
walking the nodes is not working correctly.>>>> I am doing the
following:>>>> alert("length = " + document.addForm.length);>> for (var
i = 0;i< document.addForm.length;i++)>> {>> alert("inside for loop i =
" + i);>> var e = document.addForm.elements;>> alert("e.type = "
+ e.type);>> alert("e.name = " + e.name);>> }>>>> But this doesn't
seem to find the span tag (which has an id). I assume Iam not following
the whole path.>>>> How would I change this so I would find the span
tag?>>>> Thanks,>>>> Tom>>>>> -- bruce (sqlwork.com)>>>>>> tshad
wrote:>>>> In FireFox, the length show 3 so doesn't work at all.>>>>>>>>
Not sure how to get this to work.>>>>>>>> Thanks,>>>>>>>> Tom>>>>>>>>
messageI have an aspx
window that is calling another window and I am tryingto get a couple of
objects from the opening page. The problem is that Ican't seem to get
anything inside of my form.>>>>>>>>>> I have the following in my opener
page:>>>>>>>>>> <body id="myBody" leftmargin="0" topmargin="0"
marginwidth="0"marginheight="0" runat="server">>>>>> <form id="addForm"
runat="server">>>>>> <asp:label id="theBox" text = "a test"
runat="server"/>>>>>> <asp:placeHolder ID="thePlaceHolder"
runat="server"/>>>>>> </form>>>>>> </body>>>>>>>>>>> The
"thePlaceHolder" object is where I put my User object.>>>>>>>>>> I am
trying to get to some of the objects inside of this user objectand if I
walk the Dom I can see some (but not all the objects).>>>>>>>>>> I can't
even seem to get to the "theBox" object which is one of thefirst objects
in the Dom. I tried to get the object like this:>>>>>>>>>> function
entry()>>>>> {>>>>> alert("On Entry");>>>>> var theObject =
window.opener.document.getElementById('theBox');>>>>> alert("After Entry
theObject = " + theObject);>>>>>>>>>> alert("length = " +
window.opener.document.addForm.length);>>>>>>>>>> for (var i = 0;i<
window.opener.document.addForm.length;i++)>>>>> {>>>>> alert("inside
for loop i = " + i);>>>>> var e =
window.opener.document.addForm.elements;>>>>> alert("e.type = " +
e.type);>>>>> alert("e.name = " + e.name);>>>>> }>>>>> }>>>>>>>>>>
theObject ends up being null. If I move the "theBox" object outsideof
the form, it seems to find it fine.>>>>>>>>>> When I walk the Dom, the
length is about 25 and I know there are about200 objects on the page.
Some of the objects are being shown inside of theUser control - but
"theBox" doesn't show at all. And it is one of the firstones.>>>>>>>>>>
The trace shows the first part of the objects as:>>>>>>>>>> __PAGE
ASP.ResumeSubmittalForm_aspx>>>>> _ctl1
System.Web.UI.LiteralControl>>>>> _ctl2 System.Web.UI.LiteralControl>>>>>
MyStyleSheet System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl3
System.Web.UI.LiteralControl>>>>> myBody
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl4
System.Web.UI.LiteralControl>>>>> addForm
System.Web.UI.HtmlControls.HtmlForm>>>>> _ctl5
System.Web.UI.LiteralControl>>>>> theBox
System.Web.UI.WebControls.Label>>>>> _ctl6
System.Web.UI.LiteralControl>>>>> thePlaceHolder
System.Web.UI.WebControls.PlaceHolder>>>>> _ctl0
ASP.mainPage_ascx>>>>>
_ctl0:_ctl2System.Web.UI.ResourceBasedLiteralControl>>>>> _ctl0:HomeLink
System.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl3
System.Web.UI.LiteralControl>>>>>
_ctl0:MyInformationLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl4 System.Web.UI.LiteralControl>>>>>
_ctl0:ResumeLinkSystem.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl5
System.Web.UI.LiteralControl>>>>>
_ctl0:CoverLetterLinkSystem.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl6
System.Web.UI.LiteralControl>>>>>
_ctl0:passportLinkSystem.Web.UI.WebControls.HyperLink>>>>>>>>>> The Forms
collection shows as:>>>>>>>>>> __EVENTTARGET _ctl0:_ctl1:previewLink>>>>>
__EVENTARGUMENT>>>>> __VIEWSTATE dDwzNj>>>>> _ctl0:_ctl1:resumes 0>>>>>
ctl0__ctl1_ResumeText>>>>> ctl0__ctl1_CoverLetter>>>>>
_ctl0:_ctl1:GenderList>>>>> _ctl0:_ctl1:EthnicityList>>>>>
_ctl0:_ctl1:VeteranStatus>>>>> _sk_scrollkeepervalue 0!0>>>>>>>>>> Where
is the "theBox" control and when walking the Dom it show thelength as
25.>>>>>>>>>> What is going on?????>>>>>>>>>> Is this a problem with
asp.net 1.1????>>>>>>>>>> Thanks,>>>>>>>>>> Tom>>>>>>>

 
T

tshad

tshad said:
The asp.net line is:

<asp:Label ID="objResumeText" runat="server"/>

in the View Source it is:

<span id="_ctl0_ResumeDisplay_objResumeText"></span>

Could the error be because the objResumeText is in a User control
(ResumeDisplay)?

I assume that the problem is the User Controls, because I created a Label on
my main page with id of "theLabel" and this worked fine:

var toResumeText = document.getElementById('<%=theLabel.ClientID%>');

Maybe the problem is related to the fact that you cannot even comment
problem line without getting an error which makes no sense to me.

I tried:

// var toResumeText =
document.forms[0].getElementById('<%=_ctl0_ResumeDisplay_objResumeText.ClientID%>');

and

/* var toResumeText =
document.forms[0].getElementById('<%=_ctl0_ResumeDisplay_objResumeText.ClientID%>');
*/

Both still give me the error that _ctl0_ResumeDisplay_objResumeText doesn't
exist - which it does. But even if it didn't, the commenting out should
prevent the error. This is the first time I have not been able comment a
line out.

Thanks,

Tom


Thanks,

Tom
if the ServerSide ID of your Label is MyLabel123 then use
<%=MyLabel123.ClientID%> -- verify syntax

Make sure Label is runat="server"

Lit




tshad said:
as i said, you need to use the childNodes, and a span does not have a
type or name property.

var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("tag: " + node.tagName + " id: " + nodes.id);
}

or lookup the span by id.

var theBox = document.getElementById('<%=theBox.ClientId%>');

I tried that but it gives me an error:

*******************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: // var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
*******************************************************

Here is the code:

var fromResumeText =
window.opener.document.getElementById('ctl0__ctl1_ResumeText');
var fromCoverLetter =
window.opener.document.getElementById('ctl0__ctl1_CoverLetter');
// var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');

I am looking for 2 objects on my opener page and 2 from my current page.
I can find all the objects except the 'ctl0_ResumeDisplay_objResumeText'
which is the only object that is an asp:Label.

This code worked fine except that it didn't find Label objects - it
found the other 3.

This error happened when I added the <%=...%> format.

The interesting thing is that I get the error even when I comment out
the new line and the error is on the commented out line????

***************************************************************************
Compiler Error Message: BC30451: Name 'ctl0_ResumeDisplay_objResumeText'
is not declared.

Source Error:

Line 47: var toResumeText =
document.getElementById('ctl0_ResumeDisplay_objResumeText');
Line 48: // var toResumeText =
document.getElementById('<%=ctl0_ResumeDisplay_objResumeText.ClientID%>');
Line 50: var toCoverLetter =
document.getElementById('ctl0_ResumeDisplay_objCoverLetterTextBox');
******************************************************************************************The
error is on line 48.How can that be??? It is commented out.The trace
for this page is:_ctl0:ResumeDisplay:eek:bjResumeText
System.Web.UI.WebControls.Label_ctl0:ResumeDisplay:_ctl51
System.Web.UI.LiteralControl_ctl0:ResumeDisplay:eek:bjCoverLetterTextBox
FreeTextBoxControls.FreeTextBox_ctl0:ResumeDisplay:_ctl30
System.Web.UI.LiteralControlIt says that
'ctl0_ResumeDisplay_objResumeText' doesn't exist. I don't getthe error
message if I don't use the <%=...%> format. It doesn't find it,but I
don't get an error message just a null.Thanks,Tom>> -- bruce
in messageas the post
below said, you need the id rendered (control.ClientId).>>>>>> also the
form.elements collection only contains form controls(input,select and
textarea). only form elements have a type and nameproperty.>>>>>> also
as firefox is strict, you need to specify:>>>>>>
document.addForm.elements>>>>>> to find dom objects like a span or
anchor (link), you want to walkchildNodes recursively.>>>>>>> You're
right on the span. I hadn't realized I was using a Label (when Ichanged
it to a textbox it worked fine). But I do need to get theLabel/Span and
my walking the nodes is not working correctly.>>>> I am doing the
following:>>>> alert("length = " + document.addForm.length);>> for
(var i = 0;i< document.addForm.length;i++)>> {>> alert("inside for
loop i = " + i);>> var e = document.addForm.elements;>>
alert("e.type = " + e.type);>> alert("e.name = " + e.name);>> }>>>>
But this doesn't seem to find the span tag (which has an id). I assume
Iam not following the whole path.>>>> How would I change this so I would
find the span tag?>>>> Thanks,>>>> Tom>>>>> -- bruce (sqlwork.com)>>>>>>
tshad wrote:>>>> In FireFox, the length show 3 so doesn't work at
all.>>>>>>>> Not sure how to get this to work.>>>>>>>> Thanks,>>>>>>>>
messageI have an aspx
window that is calling another window and I am tryingto get a couple of
objects from the opening page. The problem is that Ican't seem to get
anything inside of my form.>>>>>>>>>> I have the following in my opener
page:>>>>>>>>>> <body id="myBody" leftmargin="0" topmargin="0"
marginwidth="0"marginheight="0" runat="server">>>>>> <form id="addForm"
runat="server">>>>>> <asp:label id="theBox" text = "a test"
runat="server"/>>>>>> <asp:placeHolder ID="thePlaceHolder"
runat="server"/>>>>>> </form>>>>>> </body>>>>>>>>>>> The
"thePlaceHolder" object is where I put my User object.>>>>>>>>>> I am
trying to get to some of the objects inside of this user objectand if I
walk the Dom I can see some (but not all the objects).>>>>>>>>>> I can't
even seem to get to the "theBox" object which is one of thefirst objects
in the Dom. I tried to get the object like this:>>>>>>>>>> function
entry()>>>>> {>>>>> alert("On Entry");>>>>> var theObject =
window.opener.document.getElementById('theBox');>>>>> alert("After Entry
theObject = " + theObject);>>>>>>>>>> alert("length = " +
window.opener.document.addForm.length);>>>>>>>>>> for (var i = 0;i<
window.opener.document.addForm.length;i++)>>>>> {>>>>> alert("inside
for loop i = " + i);>>>>> var e =
window.opener.document.addForm.elements;>>>>> alert("e.type = " +
e.type);>>>>> alert("e.name = " + e.name);>>>>> }>>>>> }>>>>>>>>>>
theObject ends up being null. If I move the "theBox" object outsideof
the form, it seems to find it fine.>>>>>>>>>> When I walk the Dom, the
length is about 25 and I know there are about200 objects on the page.
Some of the objects are being shown inside of theUser control - but
"theBox" doesn't show at all. And it is one of the firstones.>>>>>>>>>>
The trace shows the first part of the objects as:>>>>>>>>>> __PAGE
ASP.ResumeSubmittalForm_aspx>>>>> _ctl1
System.Web.UI.LiteralControl>>>>> _ctl2
System.Web.UI.LiteralControl>>>>> MyStyleSheet
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl3
System.Web.UI.LiteralControl>>>>> myBody
System.Web.UI.HtmlControls.HtmlGenericControl>>>>> _ctl4
System.Web.UI.LiteralControl>>>>> addForm
System.Web.UI.HtmlControls.HtmlForm>>>>> _ctl5
System.Web.UI.LiteralControl>>>>> theBox
System.Web.UI.WebControls.Label>>>>> _ctl6
System.Web.UI.LiteralControl>>>>> thePlaceHolder
System.Web.UI.WebControls.PlaceHolder>>>>> _ctl0
ASP.mainPage_ascx>>>>>
_ctl0:_ctl2System.Web.UI.ResourceBasedLiteralControl>>>>> _ctl0:HomeLink
System.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl3
System.Web.UI.LiteralControl>>>>>
_ctl0:MyInformationLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl4 System.Web.UI.LiteralControl>>>>>
_ctl0:ResumeLinkSystem.Web.UI.WebControls.HyperLink>>>>> _ctl0:_ctl5
System.Web.UI.LiteralControl>>>>>
_ctl0:CoverLetterLinkSystem.Web.UI.WebControls.HyperLink>>>>>
_ctl0:_ctl6 System.Web.UI.LiteralControl>>>>>
_ctl0:passportLinkSystem.Web.UI.WebControls.HyperLink>>>>>>>>>> The
Forms collection shows as:>>>>>>>>>> __EVENTTARGET
_ctl0:_ctl1:previewLink>>>>> __EVENTARGUMENT>>>>> __VIEWSTATE
dDwzNj>>>>> _ctl0:_ctl1:resumes 0>>>>> ctl0__ctl1_ResumeText>>>>>
ctl0__ctl1_CoverLetter>>>>> _ctl0:_ctl1:GenderList>>>>>
_ctl0:_ctl1:EthnicityList>>>>> _ctl0:_ctl1:VeteranStatus>>>>>
_sk_scrollkeepervalue 0!0>>>>>>>>>> Where is the "theBox" control and
when walking the Dom it show thelength as 25.>>>>>>>>>> What is going
on?????>>>>>>>>>> Is this a problem with asp.net 1.1????>>>>>>>>>>
Thanks,>>>>>>>>>> Tom>>>>>>>


 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top