473,782 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FindControl

tma
My code below returns the .text property of the chkEqmtRental check box but
not it's checked state. I'm creating the control in a placeholder and need
to access the check box in the codebehind. Also, is it possible to access
events for that control and if so, how?
chkEqmtRental = plh.FindControl ("chkEqmtRental ")


Nov 18 '05 #1
7 4374
You code below assigns the checkbox (assuming it is found) to a variable. As
Checked is a property of the checkbox, you should have no trouble accessing
it. So, you might want to explain what you're trying to say.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"tma" <tm*@allisconfu sing.net> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
My code below returns the .text property of the chkEqmtRental check box but not it's checked state. I'm creating the control in a placeholder and need
to access the check box in the codebehind. Also, is it possible to access
events for that control and if so, how?
chkEqmtRental = plh.FindControl ("chkEqmtRental ")


Nov 18 '05 #2
tma
This what I'm trying to do:
Dim chkEqmtRental As WebControls.Che ckBox

chkEqmtRental = plh.FindControl ("chkEqmtRental ")

If chkEqmtRental.C hecked Then

....some code...

End If

Presently, the chkEqmtRental.C hecked always evaluates to FALSE.


"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:Ok******** *****@TK2MSFTNG P12.phx.gbl...
You code below assigns the checkbox (assuming it is found) to a variable. As Checked is a property of the checkbox, you should have no trouble accessing it. So, you might want to explain what you're trying to say.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"tma" <tm*@allisconfu sing.net> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
My code below returns the .text property of the chkEqmtRental check box

but
not it's checked state. I'm creating the control in a placeholder and need to access the check box in the codebehind. Also, is it possible to access events for that control and if so, how?
chkEqmtRental = plh.FindControl ("chkEqmtRental ")



Nov 18 '05 #3
hi tma,

I think that the problem is there because you don't cast the finded control
to a checkbox
so the code should be:

Dim chkEqmtRental as CheckBox = CType(plh.FindC ontrol("chkEqmt Rental"),
CheckBox)
chkEqmtRental.T ext 'for text property
chkEqmtRental.C hecked 'for checked state

what do you mean by acces the event ?

Regards
Martin
"tma" <tm*@allisconfu sing.net> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
My code below returns the .text property of the chkEqmtRental check box but not it's checked state. I'm creating the control in a placeholder and need
to access the check box in the codebehind. Also, is it possible to access
events for that control and if so, how?
chkEqmtRental = plh.FindControl ("chkEqmtRental ")


Nov 18 '05 #4
tma
With regard to events, I'm asking if it's possible to gain access to events
in the codebehind for controls added via placeholder.
"Martin Marinov" <me********@mec rossroad.bg> wrote in message
news:ub******** *****@TK2MSFTNG P11.phx.gbl...
hi tma,

I think that the problem is there because you don't cast the finded control to a checkbox
so the code should be:

Dim chkEqmtRental as CheckBox = CType(plh.FindC ontrol("chkEqmt Rental"),
CheckBox)
chkEqmtRental.T ext 'for text property
chkEqmtRental.C hecked 'for checked state

what do you mean by acces the event ?

Regards
Martin
"tma" <tm*@allisconfu sing.net> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
My code below returns the .text property of the chkEqmtRental check box

but
not it's checked state. I'm creating the control in a placeholder and need to access the check box in the codebehind. Also, is it possible to access events for that control and if so, how?
chkEqmtRental = plh.FindControl ("chkEqmtRental ")



Nov 18 '05 #5
First, I would advise you to turn Option Strict ON. It will prevent data
type errors like this. Every Checkbox has the same properties. However, the
FindControl() method returns a type of System.Web.UI.C ontrol, not
System.Web.UI.W ebControls.Chec kBox. You have to cast it as a CheckBox in
order to access the CheckBox properties.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"tma" <tm*@allisconfu sing.net> wrote in message
news:eZ******** ******@tk2msftn gp13.phx.gbl...
This what I'm trying to do:
Dim chkEqmtRental As WebControls.Che ckBox

chkEqmtRental = plh.FindControl ("chkEqmtRental ")

If chkEqmtRental.C hecked Then

...some code...

End If

Presently, the chkEqmtRental.C hecked always evaluates to FALSE.


"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:Ok******** *****@TK2MSFTNG P12.phx.gbl...
You code below assigns the checkbox (assuming it is found) to a variable.
As
Checked is a property of the checkbox, you should have no trouble

accessing
it. So, you might want to explain what you're trying to say.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"tma" <tm*@allisconfu sing.net> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
My code below returns the .text property of the chkEqmtRental check
box but
not it's checked state. I'm creating the control in a placeholder and

need to access the check box in the codebehind. Also, is it possible to access events for that control and if so, how?
chkEqmtRental = plh.FindControl ("chkEqmtRental ")




Nov 18 '05 #6
Hi tma:

Since you mentioned using a PlaceHolder control earlier I'm thinking
you might be running into problems creating controls dynamically and
adding them to the page.

The following KB article shows how to dynamically add a control and
add an event handler:
http://support.microsoft.com/default...b;EN-US;317515

Notice it also adds the control during Page_Init, which is before
Page_Load, as this can impact how the control behaves and remembers
it's state.

HTH,

--
Scott
http://www.OdeToCode.com

On Mon, 9 Aug 2004 07:17:26 -0500, "tma" <tm*@allisconfu sing.net>
wrote:
My code below returns the .text property of the chkEqmtRental check box but
not it's checked state. I'm creating the control in a placeholder and need
to access the check box in the codebehind. Also, is it possible to access
events for that control and if so, how?
chkEqmtRenta l = plh.FindControl ("chkEqmtRental ")



Nov 18 '05 #7
tma
With Option Strict On and the following lines, I still get no value for
..checked. I can define the chkEqmtRental as webcontrols.che ckbox or just
checkbox and same result. I'm at a loss. Is anyone able to make this work?
Could you post a code sample?

table = new htmltable

cell = new htmltablecell

row = new htmltablerow

chk = New WebControls.Che ckBox

chk.AutoPostBac k = True

chk.Attributes. Add("runat", "server")

chk.Text = "Equipment rental"

chk.ToolTip = "Player requested rental equipment."

chk.ID = "chkEqmtRen tal"

cell.Controls.A dd(chk)

row.Controls.Ad d(cell)

table.Controls. Add(row)

plh.controls.ad d(table)

chkEqmtRental = CType(plh.FindC ontrol("chkEqmt Rental"), CheckBox)

Cast does not return a true for .checked when box is checked.

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:ez******** *****@TK2MSFTNG P09.phx.gbl...
First, I would advise you to turn Option Strict ON. It will prevent data
type errors like this. Every Checkbox has the same properties. However, the FindControl() method returns a type of System.Web.UI.C ontrol, not
System.Web.UI.W ebControls.Chec kBox. You have to cast it as a CheckBox in
order to access the CheckBox properties.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"tma" <tm*@allisconfu sing.net> wrote in message
news:eZ******** ******@tk2msftn gp13.phx.gbl...
This what I'm trying to do:
Dim chkEqmtRental As WebControls.Che ckBox

chkEqmtRental = plh.FindControl ("chkEqmtRental ")

If chkEqmtRental.C hecked Then

...some code...

End If

Presently, the chkEqmtRental.C hecked always evaluates to FALSE.


"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:Ok******** *****@TK2MSFTNG P12.phx.gbl...
You code below assigns the checkbox (assuming it is found) to a variable.
As
Checked is a property of the checkbox, you should have no trouble

accessing
it. So, you might want to explain what you're trying to say.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"tma" <tm*@allisconfu sing.net> wrote in message
news:eR******** ******@TK2MSFTN GP09.phx.gbl...
> My code below returns the .text property of the chkEqmtRental check box but
> not it's checked state. I'm creating the control in a placeholder

and need
> to access the check box in the codebehind. Also, is it possible to

access
> events for that control and if so, how?
> chkEqmtRental = plh.FindControl ("chkEqmtRental ")
>
>
>
>
>
>



Nov 18 '05 #8

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

Similar topics

1
7783
by: James G. Beldock | last post by:
I have seen the following behavior: when issuing a Page.FindControl() for a control which exists in an item template (from within an ItemDataBound() event, for example), I get nulls back regularly. Has anyone seen this before? It's pretty aggravating to have to iterate through the controls in each grid cell to find the ones I need, especially since finding those cells is not always easy. Here's my ItemDataBound() handler: private void...
2
6566
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server" OnClick="btnAddMember_Click">Add...</asp:LinkButton> <asp:TextBox ID="txtAddMember" runat="server"></asp:TextBox>
2
8296
by: encoad | last post by:
Hi everyone, I'm slowly going mad with Masterpages and the FindControl. After a couple days of figuring out how to use the FindControl command from within a Masterpage, I still can't explain why this code does not function. As you can see if you compile it with 2005, clicking "Button" will achieve the desired result of displaying the contents of the textbox, however the test(); function called from Page_Load does not do anything. ...
11
1898
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to get the text of an item in a GridView, but am doing something wrong. Can someone help me with the correct C# statement I need? Below is my GridView and my attempt to get the control. Thank you. string option = ((TextBox)dgDropDownMenus.Items.FindControl("txtName")).Text; -----------------------DataGrid------------------------------------------- <asp:datagrid id="dgMenus" style="Z-INDEX: 101; LEFT: 0px; POSITION:
5
1817
by: daniel.hedz | last post by:
I am generating a usercontrol dynamically successfully, but when I try to find that usercontrol I get a type mismatch. This is what I am doing: //Loading my usercontrol MyWebApp.Folder.Folder.MyUsercontrol myUC = (MyWebApp.Folder.Folder.MyUsercontrol) LoadControl("~/Folder/Folder/MyUsercontrol.ascx");
1
3394
by: Dan | last post by:
Hi, I created a custom control (ParentCustomControl) which is using a custom template (implementing ITemplate interface), in the instantiateIn method of this template I create all the controls I need (Label, textboxes, button) and I also create another custom control (ChildCustomControl) which is using a custom template too. My problem comes when I'm trying to access the child Controls of ChildCustomControl with the FindControl...
14
3205
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from within my Default.aspx as follows: MyUC C = (MyUC)this.FindControl("SomeID"); When I try to run this, I get error: "The type or namespace name 'MyUC' could not be found (are you missing a
7
5701
by: AAaron123 | last post by:
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">
4
2986
by: Hillbilly | last post by:
Maybe this is or isn't some kind of bug but it sure is goofy and remains a mystery that really has me puzzled for two reasons... // goofy syntax functions as expected... Panel finalStepButton = Page.Master.FindControl("CenterPanelContent $ItemBuilderWizard $StepNavigationTemplateContainerID $StepNavFinalStepButton") as Panel;
9
2187
by: AAaron123 | last post by:
I'm this far in determining the correct code to find a textbox I need to set. Me.Master.FindControl("Body1").FindControl("Form2").FindControl("Table2").FindControl("TableRow7").FindControl("TableCellR7C2S2").FindControl("RightCPH").FindControl("div1").FindControl("div2").FindControl("LoginView1") Took me longer than I want to say to produce the above and I'm not there yet.
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.