| | |
Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 2
Reputation:
Solved Threads: 0
Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'
0
#1 Feb 21st, 2009
Hi All
I am getting below error. basically I want to loop through all controls in a page and make sure they have not changed the values. if they have i want to prompt a message asking to save.
while looping the controls I am not able to send it as a string its erroring out. can some one please suggest how to convert String to a webcontrol
--------------------------------------------------------------------------------
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: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'.
Source Error:
Line 19: For Each ctrl As Control In Page.Controls
Line 20: 'w = CType(ctrl, WebControl)
Line 21: MonitorChanges(ctrl.ID)
Line 22: Next
Line 23: End Sub
I am getting below error. basically I want to loop through all controls in a page and make sure they have not changed the values. if they have i want to prompt a message asking to save.
while looping the controls I am not able to send it as a string its erroring out. can some one please suggest how to convert String to a webcontrol
--------------------------------------------------------------------------------
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: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'.
Source Error:
Line 19: For Each ctrl As Control In Page.Controls
Line 20: 'w = CType(ctrl, WebControl)
Line 21: MonitorChanges(ctrl.ID)
Line 22: Next
Line 23: End Sub
ASP.NET Syntax (Toggle Plain Text)
Public Sub MonitorChanges(ByVal wc As WebControl) If wc Is Nothing Then Exit Sub If TypeOf wc Is CheckBoxList OrElse TypeOf wc Is RadioButtonList Then 'Add an array element for each item in the checkbox/radiobutton list For i As Integer = 0 To CType(wc, ListControl).Items.Count - 1 Page.RegisterArrayDeclaration("monitorChangesIDs", """" & String.Concat(wc.ClientID, "_", i) & """") Page.RegisterArrayDeclaration("monitorChangesValues", "null") Next Else Page.RegisterArrayDeclaration("monitorChangesIDs", """" & wc.ClientID & """") Page.RegisterArrayDeclaration("monitorChangesValues", "null") End If 'AssignMonitorChangeValuesOnPageLoad() End Sub
Last edited by peter_budo; Feb 21st, 2009 at 4:42 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
Re: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'
0
#2 Feb 22nd, 2009
•
•
Join Date: Feb 2009
Posts: 2
Reputation:
Solved Threads: 0
Re: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'
0
#3 Feb 23rd, 2009
•
•
Join Date: Dec 2008
Posts: 104
Reputation:
Solved Threads: 18
Re: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'
0
#4 Feb 23rd, 2009
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
Re: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.WebControl'
0
#5 Feb 23rd, 2009
here is the example :
Default.aspx page :
Default.aspx.cs :
you set your initial values in the class, then you compare your class values to the form values, run this example on your local pc and you will understand, you can convert the code to its VB equivalent using one of the free converters searcing google.
Default.aspx page :
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </div> </form> </body> </html>
Default.aspx.cs :
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { private class formValues { public string textbox1 = ""; public string texbox2 = ""; public bool anyChanges = false; } formValues frmValues = new formValues(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text != frmValues.textbox1) frmValues.anyChanges = true; if (TextBox2.Text != frmValues.texbox2) frmValues.anyChanges = true; Response.Write(frmValues.anyChanges.ToString()); } }
you set your initial values in the class, then you compare your class values to the form values, run this example on your local pc and you will understand, you can convert the code to its VB equivalent using one of the free converters searcing google.
Due to lack of freedom of speech, i no longer post on this website.
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: forms authentication in asp.net
- Next Thread: Extend Properties of Silverlight Controls...
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net browser button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fill flash form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers






