473,387 Members | 1,510 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.

Cast problem with HtmlControls controls

(Disclaimer: I don't use ASP.NET much, so I could be going in a very odd
direction here. Put me on the proper path if I am.)

ran into a situation where I needed to replace an asp:CheckBox with a
regular INPUT type="checkbox" control. Specifically, it is declared thus:

<input ID="chkActive" Runat="server" class="CheckBox" />

This is inside an <EditItemTemplate> in a template column in a datagrid.
When the user enters edit mode, I want to set the checked state of this
control based on the data, so I have the following code in the ItemDataBound
event handler (the reference to the image is for non-edit mode):

if ((bool)currentRow["Active"])
{
if (isEditItem)
((System.Web.UI.HtmlControls.HtmlInputCheckBox)e.I tem.FindControl("chkActive")).Checked
= true;
else
((System.Web.UI.WebControls.Image)e.Item.FindContr ol("imgActive")).ImageUrl
= "Images/Checked.gif";
}

I'm getting a "System.InvalidCastException: Specified cast is not valid" in
the attempt to turn e.item into an HtmlInputCheckBox. When I was casting to
System.Web.UI.WebControls.CheckBox it worked great. But FindControl returns
a System.Web.UI.Control, which HtmlControls derive from, so I don't
understand why my new cast fails. Any ideas? Am I missing something obvious?
I can provide more details if required.
Jan 26 '06 #1
2 3936

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:uN**************@TK2MSFTNGP15.phx.gbl...
<input ID="chkActive" Runat="server" class="CheckBox" />


Never mind. I've been beating my head against a wall for two hours and I
just realized I left off the type="checkbox" attribute. It's working fine
now....
Jan 26 '06 #2
Probably would be good practice to have a better naming convention for
your CSS classes. Seeing the word CheckBox probably didn't help with
seeing you did not have the 'type' attribute present.

Jan 26 '06 #3

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

Similar topics

8
by: VB Programmer | last post by:
I have code that changes the bkground color of the webform on page_load. Here it is: Dim Body As New HtmlGenericControl Body = CType(Page.Controls(1), HtmlGenericControl)...
0
by: Jeff Tolman | last post by:
Hi! I keep getting this error, but I'm not sure why. When I turn off the trace flag, I only get it at certain times. Even with the trace flag set to true, I don't understand the output...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
3
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the...
1
by: Al Wilkerson | last post by:
Hey, I have a Web Form with a drop down list, textbox, and search button. When click the search button an SQL server database is queried fordata. Once I have the data in a dataset I use the...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
0
by: anandv81 | last post by:
Hi, I encountered a strange problem while working on an application, the problem goes like this. I am generating a few textboxes at runtime at the server side and added to a placeholder, a...
9
by: Jim in Arizona | last post by:
I get this error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'. Using this code: Dim test3 As TextBox test3 =...
2
by: sjur | last post by:
Hi, I'm in the start-phase of implementing an ASP.NET 2.0-application which will output quite a lot of HTML to the client. The question now is whether to use the built-in HtmlControls: ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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,...

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.