473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

can't get Me.FindControl to work

Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

...snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)
Aug 19 '08 #1
7 5682
To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").FindC ontrol"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)

Aug 19 '08 #2
Your note got me closer.

First time I saw trace output.
Not sure how to recognize parents.
Mabye the part reproduced below?

I tried QuickWatch with Master.FindControl("...") with tried different
things.
aspnetForm id not work but Table1 did. So I tried :

Master.FindControl("Table1").FindControl("TableRow 9") but that didn't work.

Am I getting close or wondering afar?

Thanks for the help

__Page
ctl00
ctl00$ctl04
ctl00$Head1
ctl00$ctl00
ctl00$ctl01
ctl00$ctl02
ctl00$ctl05
ctl00$ctl03
ctl00$ctl06
ctl00$ctl07
aspnetForm
ctl00$ctl08
ctl00$Table1
ctl00$TableRow0
ctl00$TableCellR0C0S2
ctl00$TableRow1
ctl00$TableRow2
ctl00$TableCellR2C0S2
ctl00$NavigationMenu
ctl00$TableRow3
ctl00$TableCellR3C0
ctl00$TableCellR3C1
ctl00$SiteMapPath1
ctl00$TableRow4
snip...
ctl00$MainMasterDataRightID
ctl00$MainMasterDataRightID$ctl00
ctl00$TableRow8
ctl00$TableCellR8C0
ctl00$TableRow9
ctl00$TableCellR9C0
ctl00$MainMasterLeftDataID
ctl00$MainMasterLeftDataID$ctl00
ctl00$MainMasterLeftDataID$RadioButtonMission
ctl00$MainMasterLeftDataID$ctl01
ctl00$MainMasterLeftDataID$RadioButtonSchedules
ctl00$MainMasterLeftDataID$ctl02
ctl00$MainMasterLeftDataID$MissionScheduleID
ctl00$MainMasterLeftDataID$ctl03
ctl00$TableRow10


"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").FindC ontrol"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
>Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)


Aug 20 '08 #3
Typos??? Maybe. but what I couldn't get to working yesterday works OK today.
So I'm all set.

Except I'm wondering.
I find it works with or without:
<%@ MasterType VirtualPath="~/Main.master" %>

Is that some how covered in:

<%@ Page AutoEventWireup="false" Language="VB"
MasterPageFile="~/Main.master" Title="Internet Site"

CodeFile="Default.aspx.vb" Inherits="Default_aspx"
MaintainScrollPositionOnPostback="true" Trace="true" %>

I read the help about MasterType but don't fully understand it.

Is it that "Master" can return different things so what I want needs to be
specified?

Thanks for the help
"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").FindC ontrol"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
>Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)


Aug 20 '08 #4
I might have it bass ackwards but typing the Master is required to reference
controls found in the content page after the master has been merged with the
content page by the compiler which must generate separate control trees that
get merged into one; referencing controls in the MasterPage itself would not
then require typing as their type is already known. Its something like that.

Go to K. Scott Allen's definitive discussion of the topic at
http://odetocode.com/
"AAaron123" <aa*******@roadrunner.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Typos??? Maybe. but what I couldn't get to working yesterday works OK
today.
So I'm all set.

Except I'm wondering.
I find it works with or without:
<%@ MasterType VirtualPath="~/Main.master" %>

Is that some how covered in:

<%@ Page AutoEventWireup="false" Language="VB"
MasterPageFile="~/Main.master" Title="Internet Site"

CodeFile="Default.aspx.vb" Inherits="Default_aspx"
MaintainScrollPositionOnPostback="true" Trace="true" %>

I read the help about MasterType but don't fully understand it.

Is it that "Master" can return different things so what I want needs to be
specified?

Thanks for the help
"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").Find Control"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
>>Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)


Aug 20 '08 #5
Can you pull the control your trying to reference out of the HtmlTable
control and write the HTML yourself? Your control and its parent containers
will be easier to read and access. Generally speaking parent containers will
be controls templates used in the content pages.

But otherwise, keep trying with each table item like
Master.FindControl("Table1").FindControl("TableRow 9").FindControl("TableCellR9C0").FindControl("..." )
until you find it. Another way to determine a container is to read the
control's Type in the Control Tree. Its often a guessing game and trying
until you get the right containers identified. Very messy with MasterPages
"AAaron123" <aa*******@roadrunner.comwrote in message
news:uM**************@TK2MSFTNGP04.phx.gbl...
Your note got me closer.

First time I saw trace output.
Not sure how to recognize parents.
Mabye the part reproduced below?

I tried QuickWatch with Master.FindControl("...") with tried different
things.
aspnetForm id not work but Table1 did. So I tried :

Master.FindControl("Table1").FindControl("TableRow 9") but that didn't
work.

Am I getting close or wondering afar?

Thanks for the help

__Page
ctl00
ctl00$ctl04
ctl00$Head1
ctl00$ctl00
ctl00$ctl01
ctl00$ctl02
ctl00$ctl05
ctl00$ctl03
ctl00$ctl06
ctl00$ctl07
aspnetForm
ctl00$ctl08
ctl00$Table1
ctl00$TableRow0
ctl00$TableCellR0C0S2
ctl00$TableRow1
ctl00$TableRow2
ctl00$TableCellR2C0S2
ctl00$NavigationMenu
ctl00$TableRow3
ctl00$TableCellR3C0
ctl00$TableCellR3C1
ctl00$SiteMapPath1
ctl00$TableRow4
snip...
ctl00$MainMasterDataRightID
ctl00$MainMasterDataRightID$ctl00
ctl00$TableRow8
ctl00$TableCellR8C0
ctl00$TableRow9
ctl00$TableCellR9C0
ctl00$MainMasterLeftDataID
ctl00$MainMasterLeftDataID$ctl00
ctl00$MainMasterLeftDataID$RadioButtonMission
ctl00$MainMasterLeftDataID$ctl01
ctl00$MainMasterLeftDataID$RadioButtonSchedules
ctl00$MainMasterLeftDataID$ctl02
ctl00$MainMasterLeftDataID$MissionScheduleID
ctl00$MainMasterLeftDataID$ctl03
ctl00$TableRow10


"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").Find Control"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
>>Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)


Aug 20 '08 #6

"HillBilly" <so******@somewhere.comwrote in message
news:Ov****************@TK2MSFTNGP02.phx.gbl...
Can you pull the control your trying to reference out of the HtmlTable
control and write the HTML yourself?
I don't know what this means. A way of doing it without FindControl maybe??
>Your control and its parent containers will be easier to read and access.
Generally speaking parent containers will be controls templates used in the
content pages.

But otherwise, keep trying with each table item like
Master.FindControl("Table1").FindControl("TableRow 9").FindControl("TableCellR9C0").FindControl("..." )
until you find it. Another way to determine a container is to read the
control's Type in the Control Tree. Its often a guessing game and trying
until you get the right containers identified. Very messy with MasterPages

As I mentioned in the other post I did succeed. And I noticed you pulled the
correct format from the tree without any trouble!

Thanks
>

"AAaron123" <aa*******@roadrunner.comwrote in message
news:uM**************@TK2MSFTNGP04.phx.gbl...
>Your note got me closer.

First time I saw trace output.
Not sure how to recognize parents.
Mabye the part reproduced below?

I tried QuickWatch with Master.FindControl("...") with tried different
things.
aspnetForm id not work but Table1 did. So I tried :

Master.FindControl("Table1").FindControl("TableRo w9") but that didn't
work.

Am I getting close or wondering afar?

Thanks for the help

__Page
ctl00
ctl00$ctl04
ctl00$Head1
ctl00$ctl00
ctl00$ctl01
ctl00$ctl02
ctl00$ctl05
ctl00$ctl03
ctl00$ctl06
ctl00$ctl07
aspnetForm
ctl00$ctl08
ctl00$Table1
ctl00$TableRow0
ctl00$TableCellR0C0S2
ctl00$TableRow1
ctl00$TableRow2
ctl00$TableCellR2C0S2
ctl00$NavigationMenu
ctl00$TableRow3
ctl00$TableCellR3C0
ctl00$TableCellR3C1
ctl00$SiteMapPath1
ctl00$TableRow4
snip...
ctl00$MainMasterDataRightID
ctl00$MainMasterDataRightID$ctl00
ctl00$TableRow8
ctl00$TableCellR8C0
ctl00$TableRow9
ctl00$TableCellR9C0
ctl00$MainMasterLeftDataID
ctl00$MainMasterLeftDataID$ctl00
ctl00$MainMasterLeftDataID$RadioButtonMission
ctl00$MainMasterLeftDataID$ctl01

ctl00$MainMasterLeftDataID$RadioButtonSchedules
ctl00$MainMasterLeftDataID$ctl02
ctl00$MainMasterLeftDataID$MissionScheduleID
ctl00$MainMasterLeftDataID$ctl03
ctl00$TableRow10


"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").Fin dControl"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe>
</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)


Aug 21 '08 #7
I think it saves add CType.
But I have this in my .aspx
Note it is commented out.
The comments are Allen's
<%--<%@ MasterType VirtualPath="~/Main.master" %>--%>

<%--<%@ MasterType VirtualPath="~/otc.master" %>

Now when ASP.NET codegens the page, it puts the following inside a partial
class definition.

Public Shadows ReadOnly Property Master() As otc

Get

Return CType(MyBase.Master,otcMaster)

End Get

End Property

--%>

And this in my .vb

frame1 =
Me.Master.FindControl("Table1").FindControl("Table Row9").FindControl("TableCellR9C0").FindControl("M ainMasterLeftDataID").FindControl("MissionSchedule ID")

and it works OK.

Seems I should need a CType around Me.Master.

It's academic at this point but interesting.

thanks


"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I might have it bass ackwards but typing the Master is required to
reference controls found in the content page after the master has been
merged with the content page by the compiler which must generate separate
control trees that get merged into one; referencing controls in the
MasterPage itself would not then require typing as their type is already
known. Its something like that.

Go to K. Scott Allen's definitive discussion of the topic at
http://odetocode.com/
"AAaron123" <aa*******@roadrunner.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>Typos??? Maybe. but what I couldn't get to working yesterday works OK
today.
So I'm all set.

Except I'm wondering.
I find it works with or without:
<%@ MasterType VirtualPath="~/Main.master" %>

Is that some how covered in:

<%@ Page AutoEventWireup="false" Language="VB"
MasterPageFile="~/Main.master" Title="Internet Site"

CodeFile="Default.aspx.vb" Inherits="Default_aspx"
MaintainScrollPositionOnPostback="true" Trace="true" %>

I read the help about MasterType but don't fully understand it.

Is it that "Master" can return different things so what I want needs to
be specified?

Thanks for the help
"HillBilly" <so******@somewhere.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>To find controls in the content page:

1st we have to ensure we type the Master in the content page...
<%@ MasterType VirtualPath="~/Masters/MasterPage.master" %>

2nd enable trace in the content page and observe all of the parent
containers using the FindControl on each of them...

Master.FindControl("...").FindControl("...").Fin dControl"MissionScheduleID")


"AAaron123" <aa*******@roadrunner.comwrote in message
news:uZ**************@TK2MSFTNGP02.phx.gbl...
Me.FindControl("MissionScheduleID"), below returns null.

Do you know what I'm doing wrong?

Thanks

***In my .aspx file I have:

asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID"
runat="server">

<div class="MainMasterDataAqua">

..snip...RadioButtons

</div>

<br />

<iframe runat="server" id="MissionScheduleID" frameborder="0"
src="Schedule.htm" width="100%" height="100%" </iframe>
</asp:Content>

***In the .vb file:

Protected WithEvents frame1 As
System.Web.UI.HtmlControls.HtmlGenericControl

Protected Sub RadioButtonMission_CheckedChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles RadioButtonMission.CheckedChanged

frame1 = CType(Me.FindControl("MissionScheduleID"), HtmlControl)


Aug 21 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark D'Souza via .NET 247 | last post by:
In trying to create a Panel object with the FindControl methodusing a string variable as the paramater. The code is below. The variable 'testvariable' is equal to pnl_0 which is anexisting Panel on...
1
by: tshad | last post by:
I am using sample code from C# and am trying to convert it to VB.Net in my aspx page. This works in C#: DataGrid oGrid = (DataGrid)oItem.FindControl("DataGrid1"); I have tried all kinds of...
3
by: Shapper | last post by:
Hello, I have a third party control in my page. I need to set the properties of Labels and Images in this control when: 1. User enters the Page. 2. A button is clicked which changes culture...
24
by: Dennis | last post by:
I'm trying to use FindCrontrol and it will not work. Here is the code: Dim DisplayPanel As Panel DisplayPanel = CType(FindControl("pnlName"), Panel) No matter how I do it - I've tried...
4
by: Dave | last post by:
If you had a FileUpload control inside of a FormView...how would you use FindControl to access the FileUpload properties? Let me just say that...
4
by: Jim McGivney | last post by:
I am trying to form a string by concatenating the Text strings of a number of Label controls. The Labels are Label33 to Label64. I thought I would use a For Loop to increment through the labels. ...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
2
by: Jeff | last post by:
hi asp.net 2.0 I'm having trouble with findcontrol. The problem is in the code below. The is that this line don't work: label = (Label)e.Item.FindControl("lblKode"); label has a NULL value...
9
by: AAaron123 | last post by:
I'm this far in determining the correct code to find a textbox I need to set. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.