BC30311: Value of type 'Control' cannot be converted to 'System.Web.UI.WebControls.CheckBox'

 Hi, can somebody help me on this problem. It works at first, but all of a sudden, it fails, and I can't find out why.

 

 

1     Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
2    
3            If Not CheckRequiredField() Then
4                MessageBox("Please complete the input data!")
5                Exit Sub
6            End If
7    
8            Dim nRow As Integer
9            Dim Ctrl As Control
10           Dim chkDelete As Object
11           Dim LookupID, Name, Desc, Type As String
12   
13           nRow = 0
14   
15           For Each Ctrl In phLookUp.Controls
16   
17               If Ctrl.GetType() Is GetType(CheckBox) Then
18   
19                   '   Checked    = Request.Form("chkDelete" & nRow)
20                   LookupID = Request.Form("txtLookupID" & nRow)
21                   Name = Request.Form("txtName" & nRow)
22                   Desc = Request.Form("txtDesc" & nRow)
23                   Type = Request.Form("txtType" & nRow)
24   
25                   If CType(Ctrl, CheckBox).Checked Then '--> This is the line that causes error
26                       '
27                       'delete
28                       strSQL = "DELETE esd_lookup " & _
29                                "WHERE lookup_id = " & LookupID
30   
31                       objAdapter = New System.Data.OracleClient.OracleCommand(strSQL, objConnection)
32   
33                       objRec = objAdapter.ExecuteReader()
34   
35                       objRec.Close()
36   
37                   Else
38   
39                       If LookupID = "New" Then
40                           'insert
41                           strSQL = "INSERT INTO esd_lookup " & _
42                                    "(lookup_id,lookup_type,lookup_desc,lookup_name)" & _
43                                    " (select lookup_seq.nextval, '" & _
44                                    UCase(Type) & "','" & _
45                                    Desc & "','" & _
46                                    Name & "' from dual) "
47   
48                           objAdapter = New System.Data.OracleClient.OracleCommand(strSQL, objConnection)
49   
50                           objRec = objAdapter.ExecuteReader()
51   
52                           objRec.Close()
53   
54                       Else
55                           'update
56                           strSQL = "UPDATE esd_lookup " & _
57                                    "SET lookup_desc = '" & Desc & "' " & _
58                                    ",lookup_name = '" & Name & "' " & _
59                                     "where lookup_id = '" & LookupID & "'"
60   
61                           objAdapter = New System.Data.OracleClient.OracleCommand(strSQL, objConnection)
62   
63                           objRec = objAdapter.ExecuteReader()
64   
65                           objRec.Close()
66   
67                       End If
68   
69                   End If
70   
71                   nRow += 1
72   
73               End If
74   
75           Next
76   
77           Select Case Type
78               Case "MACHINE"
79                   Type = "Machine"
80   
81               Case Else
82   
83           End Select
84   
85   
86   
87           txtItemCountAdd.text = 0
88           Call Header()
89           Call Item(Type)
90   
91       End Sub

 

1
svanistelrooy901
1/24/2008 1:55:00 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

7 Replies
3453 Views

Similar Articles

[PageSpeed] 25

Maybe instead of this...

Dim Ctrl As Control
You can try this...
Dim Ctrl As WebControl 

 

1
Galoopta
1/24/2008 3:20:59 AM

 

 It solve the initial problem, but then new problem arise, which stated

"Unable to cast object of type 'System.Web.UI.HTMLControls.HtmlGenericControls' to type 'System.Web.UI.WebControls.WebControl'

It comes from this line

For Each Ctrl In phLookUp.Controls
 

 

0
svanistelrooy901
1/24/2008 3:47:55 AM

Looks like it should work, since WebControl also inherits from Control. Are you using any custom controls in your phLookup placeholder that inherits from checkbox? If so that would probably cause this error.

-1
Snowst
1/24/2008 3:49:02 AM

Web Server controls and HTML Controls  cannot be mixed. If I were you, I would replace your HTML controls with their Web Server equivalent.  You should only use HTML controls if you need to do heavy client-side Javascript or converting an old ASP application to .NET .

 

Please do not forget to "Mark as correct answer" if your issue has been resolved. 

1
Galoopta
1/24/2008 4:03:45 AM

I think it does use web server control Galoopta (by the way, i don't write the code, someone else did). I could be wrong. Glad to show the entire code of the page if you want to. The thing is, it works well before this, even yesterday. But suddenly gives error. I'm clueless right nowConfused  

-1
svanistelrooy901
1/24/2008 6:22:15 AM

I change the codeline...

 

Dim Ctrl As Control
 

To...

 

Dim Ctrl As System.Web.UI.Control
 

It works. But I don't understand why putting the Imports System.Web.UI.Control or Imports System.Web.UI statement at the top didn't work.

 
1
svanistelrooy901
1/24/2008 6:53:14 AM
Glad you got it working but like you said, that should not make a difference unless you are getting your scope mixed up with some other control named "Ctrl"
1
Galoopta
1/27/2008 7:50:54 PM
Reply:

Similar Artilces:

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.
I have a pretty basic vb.net page that includes a listview.  (Note, this is my first time working with listview, so I may have some of the terminology wrong).  In my list view, I display all the important data for each record, and ask the user to provide a status for each record by including a radiobutton list with various responses.  At the bottom of the page is one submit button, and when the user clicks submit, I'm saving each records value based upon which response is selected in the radiobutton list. My saving of data is working,  but I'm getting an error when i try to display a confirmation message that includes a label with each records selected value from the radiobutton list.  Any idea what I'm doing wrong and why I can't grab the value selected and display it ??  I'm bolding the line that throws the error.. My Code Behind.. Protected Sub updateResponse()For Each Item As ListViewItem In lvAudits.ItemsDim rList As RadioButtonList = CType(Item.FindControl("rbAnswer"), RadioButtonList)Dim lblAnswer As Label = rList.SelectedValue.ToStringlblAnswer.Visible = True Dim tblAnswer As Table = CType(Item.FindControl("tblAnswerArea"), Table)tblAnswer.Visible = FalseDim conn As SqlConnectionDim comm As SqlCommandDim reader As SqlDataReaderDim connectionString As String = ConfigurationManager.ConnectionStrings("xxxxConnectionString").ConnectionStringconn = New SqlConnection(con...

BC30311: Value of type 'System.Web.UI.WebControls.RadioButtonList' cannot be converted to 'String'.
I have a listview that I'm working with.  Each record returned by my sql query is displayed in my list view as text, with the exception of one field, which I need to display as a radiobutton list.  I tried to set the value of the radiobutton in my codebehind, but keep getting errors.  How do I tell this radiobutton list that the value that should be selected when the page loads is equal to the value returned from my sql query?    The line in bold throws the error... How am I supposed to indicate what value to have selected when the page loads? <asp:RadioButtonList ID="rbAnswer" runat="server"><asp:ListItem Text="Not Yet Answered" Value="Not Yet Answered" ></asp:ListItem><asp:ListItem Text="No Information" Value="No Information"></asp:ListItem><asp:ListItem Text="Yes, Will Reply Now" Value="Will Reply Now"></asp:ListItem><asp:ListItem Text="Yes, Will Send Later" Value="Will Send Later"></asp:ListItem></asp:RadioButtonList> Here's what I tried in my code behind.. For Each Item As ListViewItem In lvAudits.ItemsDim rb As RadioButtonList = CType(Item.FindControl("rbAnswer"), RadioButtonList)rb.SelectedValue = CType(Item.FindControl("rbAnswer"), RadioButtonList)NextNever make important decisions on a Monday! rb.SelectedValue = CType(Item.FindControl("rbAn...

BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'.
 Hello everyone, I receive the error in the subject when viewing this page, I can get it to work fine without the master page and only the textboxes, but that causes an error with line 11, even when the page contents do process to the form. I don`t understand the error and I would appreciate any guidance on this. Thanks for reading.1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %> 2 3 <script runat="server"> 4 5 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 6 Dim D...

Having an error: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.
Error Message: Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'. Line 13: myGetRandom.RetrieveDetails(lblQuestion.text, lblAnswers.text, lblViewCount.text, lblLastUpdated.text) Sub Page_Load Dim myGetRandom as new GetRandom myGetRandom.RetrieveDetails(lblQuestion.text, lblAnswers.text, lblViewCount.text, lblLastUpdated.text) End Sub Code behind Sub RetrieveDetails(lblQuestion as label, _ lblAnswers as label, _ lblViewCount as label, _ lblLastUpdated as...

Error Serializing Value 'System.Web.UI.WebCOntrols.TreeNode' of type 'System.Web.UI.WebCOntrols.TreeNode'
Hi, I am  getting the error stated in the subject when i am storing a TreeNode in a ViewState and then using it as follows if (ViewState["ProductCounty"]!=null) { TreeNode _productCountyNode = DataTree.FindNode(((TreeNode)ViewState["ProductCounty"]).ValuePath); _productCountyNode.Expand(); } what could be causing this error? Hi, I believe TreeNode isn't serializable in a way its required for objects which can be put to ViewState - as reference - (TreeNode implements IStateManager and is meant to work together with TreeView itself saving it...

Compiler Error Message: BC30311: Value of type 'System.Web.UI.Control' cannot be converted to 'IWizardStep'.
I am working with a Book ASPNET 2.0 Unleashed "by the way, great book". There code is witten with <script> tags and the vb is in the same page as the Html. So, as practice, I am simply trying to convert it to code behind... The page calls a class named "IWizardSetp" See both there code and my convered code below. I get the following error. What am I doing wrong? Details please if you can help... Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details a...

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox'
I am attempting to "Update" a field in a Datagrid, but no matter what I do (Using either Label or Text Boxes)  I keep getting the same error: Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox' The Error is highlighted below in the Sub... <==THE FIELD THAT CALLS THE ERROR  Any help would be greatly appreciated !!! Thanks !!   The code is as follows... <table border=0 height=210 bordercolor=olive ><tr valign=top><td> <asp:datagrid id="FacilityDataGrid" runat="server" Font-Names="Arial" Font-Size="11px" HorizontalAlign="Left" ItemStyle-Font-Size="x-small" HeaderStyle-Font-Bold="True"HeaderStyle-Font-Size="x-small" AlternatingItemStyle-BackColor="#FFFFFF" Cellpadding="0" BorderWidth="0"AutoGenerateColumns="False" BorderStyle="None" GridLines="None" BorderColor="#404040" Width="75%"DataKeyField="FacilityID"OnUpdateCommand="MyDataGrid_UpdateCommand"OnCancelCommand="MyDataGrid_CancelCommand"OnEditCommand="DG_Combo_Edit"> <AlternatingItemStyle BackColor="#FFFFFF"></AlternatingItemStyle><ItemStyle Font-Size="X-Small"></ItemStyle><HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeCo...

Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Hi,  I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method. I get the following error in the line below that is in italics and underlined: Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.   Here is my code: ddl_iFullname = New DropDownList ddl_iFullname.ID = "ddl_iFullname" ddl_iFullname.DataSource = ObjectDataSource3 ddl_iFullname.DataTextField = "fullname" ddl_iFullname.DataValueField = "...

Value of type 'Integer' cannot converted to 'System.Web.UI.WebControls.Unit'
I'd like to dynamically change the size of controls such as panel.In the code I putmainPage.Height = 500  'mainPage is a PanelHowever, it failed to compile with message;Value of type 'Integer' cannot converted to 'System.Web.UI.WebControls.Unit'How can I change the code so that it compiles? mainPage.Height = Unit.Pixel(500)  'mainPage is a PanelSonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Controls Forum It works very well. Thanks a lot....

Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'
I have a new page (wireframe) based on the User_Create page in the Time Tracker starter kit.  I have no code in the code behind page.  What might be causing this error?  This newbie needs help. I had a TextBox control named "Title" which appearantly conflicted with the page title. thanks!!! ...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'
Hello, Goal: enter a number in two fields HoursPerUnit and PeoplePerUnit and the value for the third field, TotalHoursPerUnit will populate after the the number in the two fields have been caculated.  Using the code below I receive the error message above.  Please tell me what am I doing wrong? Do I need to cast the text as a literal?  Please help? Thank you in advance, <%@ Page Language="VB" MasterPageFile="Default.master" AutoEventWireup="false" CodeFile="frmHR.aspx.vb" Inherits="frmHR" title="HR" %><asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">    HR<br /><script language =javascript  type="text/javascript">function Calculate(HoursPerUnit, PeoplePerUnit, TotalHoursPerUnit){    TotalHoursPerUnit.value = HoursPerUnit.value * PeoplePerUnit.value;}   </script>    <br />    <asp:LinkButton ID="CheckAll" runat="server">Check All</asp:LinkButton>    <asp:LinkButton ID="UncheckAll" runat="server">Uncheck All</asp:LinkButton><br />    &nbsp;<br />    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="HR...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
Hi, any idea why I'm getting the following error?Line 45: protected void CartGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) Line 46: { Line 47: TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0]; Line 48: int Quantity = Convert.ToInt32(QuantityTextBox.Text); Line 49: Are you sure that the control at CartGrid.Rows[e.RowIndex].Cells[2].Controls[0] isn't a LiteralControl?  How are you creating code this in your code?Brent JenkinsASP.NET, C#, Web Developerwww.valewebdesign.co.uk  ...

Compiler Error Message: BC30311: Value of type 'System.Web.UI.DataSourceSelectArguments' cannot be converted to 'Integer'.
 Hello, I'm wondering if someone can help me figure out why I'm receiving the above error message..."Compiler Error Message: BC30311: Value of type 'System.Web.UI.DataSourceSelectArguments' cannot be converted to 'Integer'." In visual web developer, the blue line is pointing out the variables args, on line 15.   1 Imports System.Data 2 Partial Class POS_so_Default 3 Inherits System.Web.UI.Page 4 5 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 6 customer...

Cannot convert type 'System.Web.UI.Control' to 'FileUpload'
Hi,I'm getting an error in the follow code:FileUpload fileUpload1 = (FileUpload)itemPanel.FindControl("fuDoc");Where itemPanel is a AjaxControlToolkit.TabPanel and the aspx code is: <asp:FileUpload ID="fuDocument_es" runat="server" />The error is Cannot convert type 'System.Web.UI.Control' to 'FileUpload' Why? Thanks You are trying to find and convert "fuDoc" or "fuDocument_es"  ?try thisFileUpload fileUpload1 = (FileUpload)itemPanel.FindControl("fuDocument_es");...

Cannot convert type 'System.Web.UI.WebControls.TableCell' to 'byte[]' !!!
            //Get image data from gridview column.            //byte[] imageData;            //(int a []) GridView1.Rows[e.RowIndex].Cells[2];            byte[] imageData = (byte[])GridView1.Rows[e.RowIndex].Cells[1]; <-- Having Error HERE!                         ...

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'
I have a datagridLabel ID1 = (Label)(e.Item.FindControl("ID1")); Label Name1 = (Label)(e.Item.FindControl("Name1")); Label TableName = (Label)(e.Item.FindControl("TableName"));   No0w Iam trying to TBTableName.Text = lblTableName;                  tbid.Text = lblImageTypeID1;                   tbnameordes.Text = lblImageName1; I have tried l lbltablename.text,.tostring,convert.t...

Cannot implicitely convert type 'string' to 'System.Web.UI.WebControls.Label'
 I'm starting to make a website for users to login. Once they login, I'm showing their profile. So I populate some asp:label controls on Page_Load. My profile page (shown after the user logs in) contains: <%@ Page Language="C#" MasterPageFile="~/site.master" CodeFile="clientProfile.aspx.cs" Inherits="clientProfile" AutoEventWireup="true" Title="Car Look - Your profile" %> <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server"> <div> &l...

Cannot implicitly convert type 'Login' to 'System.Web.UI.WebControls.Login'
hello  i have got this error on this part of code :protected void Wizard1_NextButtonClick(object sender, System.Web.UI.WebControls.WizardNavigationEventArgs e) {if (e.CurrentStepIndex == 0) {System.Web.UI.WebControls.Login l = (Login)Wizard1.FindControl("Login1");if (Membership.ValidateUser(l.UserName, l.Password)) { FormsAuthentication.SetAuthCookie(l.UserName, l.RememberMeSet);e.Cancel = false; } else {l.InstructionText = "Your login attempt was not successful. Please try again."; l.InstructionTextStyle.ForeColor = System.Drawing.Color.Red;e.Cancel = ...

Error: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label
Here is the code:Dim dato_start_2 as DateTime Dim varighet_str as string Dim dato_differanse as string dato_start_2 = tabell_2.Rows(DataGrid1.SelectedIndex).Item("dato_tid_sendt") dato_differanse = DateDiff(DateInterval.Day, dato_start_2, now) Label12 = "" & dato_differanse & ""  ........and theCompiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.Why and how?RegardsLars/Norway To set a text for a Label you need to use its Text property, in your code you try to set the Label to a Text and that is the reason why you g...

Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.TextBox'
Can anyone tell me what this error message means, and what to do to correct it.  Here is the code that has the error:  Dim sql As Stringsql = "INSERT INTO tblConnecting (Date, Member, Name, Company, Phone, Fax, Address, NamesofAttendees, PaymentType, Email) " _ & "Values('" & Today() & "', '" & blnMember & "', '" & Me.txtName.Text & "', '" & Me.txtCompany.Text & "', '" _& Me.txtPhone.Text & "', '" & Me.txtFax.Text &...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Web resources about - BC30311: Value of type 'Control' cannot be converted to 'System.Web.UI.WebControls.CheckBox' - asp.net.getting-started

Resources last updated: 3/5/2016 8:35:38 PM