473,387 Members | 1,606 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,387 software developers and data experts.

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 4334
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*@allisconfusing.net> wrote in message
news:eR**************@TK2MSFTNGP09.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.CheckBox

chkEqmtRental = plh.FindControl("chkEqmtRental")

If chkEqmtRental.Checked Then

....some code...

End If

Presently, the chkEqmtRental.Checked always evaluates to FALSE.


"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ok*************@TK2MSFTNGP12.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*@allisconfusing.net> wrote in message
news:eR**************@TK2MSFTNGP09.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.FindControl("chkEqmtRental"),
CheckBox)
chkEqmtRental.Text 'for text property
chkEqmtRental.Checked 'for checked state

what do you mean by acces the event ?

Regards
Martin
"tma" <tm*@allisconfusing.net> wrote in message
news:eR**************@TK2MSFTNGP09.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********@mecrossroad.bg> wrote in message
news:ub*************@TK2MSFTNGP11.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.FindControl("chkEqmtRental"),
CheckBox)
chkEqmtRental.Text 'for text property
chkEqmtRental.Checked 'for checked state

what do you mean by acces the event ?

Regards
Martin
"tma" <tm*@allisconfusing.net> wrote in message
news:eR**************@TK2MSFTNGP09.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.Control, not
System.Web.UI.WebControls.CheckBox. 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*@allisconfusing.net> wrote in message
news:eZ**************@tk2msftngp13.phx.gbl...
This what I'm trying to do:
Dim chkEqmtRental As WebControls.CheckBox

chkEqmtRental = plh.FindControl("chkEqmtRental")

If chkEqmtRental.Checked Then

...some code...

End If

Presently, the chkEqmtRental.Checked always evaluates to FALSE.


"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ok*************@TK2MSFTNGP12.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*@allisconfusing.net> wrote in message
news:eR**************@TK2MSFTNGP09.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*@allisconfusing.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?
chkEqmtRental = 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.checkbox 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.CheckBox

chk.AutoPostBack = True

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

chk.Text = "Equipment rental"

chk.ToolTip = "Player requested rental equipment."

chk.ID = "chkEqmtRental"

cell.Controls.Add(chk)

row.Controls.Add(cell)

table.Controls.Add(row)

plh.controls.add(table)

chkEqmtRental = CType(plh.FindControl("chkEqmtRental"), CheckBox)

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

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ez*************@TK2MSFTNGP09.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.Control, not
System.Web.UI.WebControls.CheckBox. 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*@allisconfusing.net> wrote in message
news:eZ**************@tk2msftngp13.phx.gbl...
This what I'm trying to do:
Dim chkEqmtRental As WebControls.CheckBox

chkEqmtRental = plh.FindControl("chkEqmtRental")

If chkEqmtRental.Checked Then

...some code...

End If

Presently, the chkEqmtRental.Checked always evaluates to FALSE.


"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Ok*************@TK2MSFTNGP12.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*@allisconfusing.net> wrote in message
news:eR**************@TK2MSFTNGP09.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
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...
2
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server"...
2
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...
11
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....
5
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...
1
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...
14
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...
7
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"...
4
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 =...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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.