Cannot convert type 'type' to 'type'

I am learning all of this, so I am still fresh, so please bear with me :)

I have a page that has some txtboxes in it, simple registration form, and I have a button that will save those txt boxes to the db. 

I am using:
- I am using Visual Web Developer 2008 Express Edition
- C#

 
When I try to compile the project I get error: Cannot convert type 'System.Web.UI.WebControls' to 'String' 

This is content of my web.config

   

  <profile>
      <properties>
        <add name="FirstName"/>
        <add name="LasttName"/>        
        <add name="Address1"/>
        <add name="Address2"/>
        <add name="City"/>
        <add name="StateProvince"/>
        <add name="ZIPPostalCode"/>
        <add name="Country" defaultValue="USA"/>
      </properties>
    </profile>
 
 And this is code that I used for it:
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class osobniprofi_registracija : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Profile.FirstName = txtFirstName;
        Profile.LastName = txtLastName;
        Profile.Address1 = txtAddress1;
        Profile.Address2 = txtAddress2;
        Profile.City = txtCity;
        Profile.StateProvince = txtState;
        Profile.ZIPPostalCode = txtPostalCode;
        Profile.Country = txtCountry;
    }
    
}
  
  
0
wex
2/20/2009 8:38:39 AM
asp.net.getting-started 91979 articles. 2 followers. Follow

1 Replies
498 Views

Similar Articles

[PageSpeed] 1

hi wex-alpha,

try to understand the error location and error by reading the error message itself.

Your error message is saying that Cannot convert type 'System.Web.UI.WebControls' to 'String' 

So , somewhere in your code you are trying to convert a webcontrol to string.

The code showing the error,

Profile.FirstName = txtFirstName;
and all teh following lines.

See, txtFirstName is the textbox name not the text in the textbox and Profile.FirstName expects a string but you are passing a textbox to it.

just modify like below,

Profile.FirstName = txtFirstName.Text

 

You are done


Joydeep Sen
Dotnet Developer

Dont forget to click “Mark as Answer” on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers


0
joydeepsen
2/20/2009 10:30:54 AM
Reply:

Similar Artilces:

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Unable to cast object of type 'TYPE' to type 'TYPE'.
I've got a custom class and collection...I want to use them to databind a Grid, and persist the state using a Session variable.  However I keep getting the above error **Sometimes...There will be times when it works fine, and times when it totally craps out.System.InvalidCastException: Unable to cast object of type 'ApprovalCycleCollection' to type 'ApprovalCycleCollection'. This should work fine, no?  I want a property to use in all my foreach loops   public ApprovalCycleCollection NewApprovalCycle { get { if (Se...

Operator '=' is not defined for type 'Char' and type 'Boolean'.
Hello, In my application when i click the button i'm getting this " Operator '=' is not defined for type 'Char' and type 'Boolean'. " But when i test it locally there is no problem at all!!!! Please tell me why this error is occuring...Thanks SwapnaPlease click "mark as answer" if this post helped you. swapnasamsonvarkey: Hello, In my application when i click the button i'm getting this " Operator '=' is not defined for type 'Char' and type 'Boolean'. " But when i test it lo...

Operator '*' is not defined for type 'DBNull' and type 'Decimal'.
 I am getting an error from the following line   <asp:Label ID="Label1" runat="server" Text='<%# String.Format("{0:C}", Eval("ProductQty") * Eval("Price"))   %>' ></asp:Label> I think I may need to convert/define the Variables but not quite sure how to do it. Any help would be great. it's not a matter of converting...its the fact that the value from the DB is Null... You'll have to wrap an IF check around it or change your query to return 0 instead of Null. If the field ...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

value of type 'XXX' cannot be converted to type 'XXX'
 I've had this issue with VS2008 lately that is driving me crazy.  I have a website where I built a class that does all my Web Service interaction.  This class returns instances of Web Service proxies, or list of the same.  In my web page I'll create a temporary variable (Dim - I'm using VB) with the same type that my service class is going to return.  When I assign my variable to the return of the method, I'm getting a message similar to the following"Value of type 'Namespace.Foo' cannot be converted to type 'Namespace.Foo'. ...

Operator '>' is not defined for type 'DBNull' and type 'Integer'.
this is my code I don't get why I'm getting this error SubModel is a number :   Example : 823 If Ds.Tables(0).Rows(0).Item("SubModel") > 0 Then Dim crst As New DataSet SqlStr = "SELECT SubModelName FROM SubModel,AcesData WHERE AcesData.SubModel = SubModel.SubModelID and (SubModelID = ?)" Dim da2 As New Data.OleDb.OleDbDataAdapter(SqlStr, conn) da2.SelectCommand.Parameters.Add("?", Data.OleDb.OleDbType.VarChar).Value = Ds.Tables(0).Rows(0).Item("SubModel")...

error: Object of type 'Object' cannot be converted to type 'Array'.
I'm getting the error listed in the subject of this post that is occurring due to a a conflict between Mootools and the .NET-generated JS when using AJAX as described in the following link: http://dev.mootools.net/ticket/553 To get a detailed view of the error, open the following page in Firefox and use Firebug to see the error details.  IE will just show the error icon at the bottom left of the window and it doesn't give much detail about the error.http://www.compasslearning.com/customersite/icg/checklist.aspx?list=1 The collision is occurring on line 5762 of the "Script...

I get Conversion from type 'DBNull' to type 'String' is not valid.
I get the following errors when I try and access certain pages.  It is caused by not populating all the text boxes with data and subsequent viewing causes these conversion errors.  Does any one else experience this?  How have you guys worked around this problem? Conversion from type 'DBNull' to type 'String' is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Conversion f...

E2094 'operator+' not implemented in type 'XXX' for arguments of type 'int'
Okay I have a problem; I am trying to extend a string class that I wrote for a friend so I can use it another project I am working on. I have an error that makes absolutely no sense. Here is the code for the copy constructor: String(const String &str) // for copying into a new string object { Size = str.Size; Data = new char[Size+1]; for (int i = 0; i<Size; i++) Data[i] = str[i]; // recieving the following error on the above line: [BCC32 Error] Mystring.h(33): // E2094 'operator+' not implemented in type 'String' for arguments of typ...

Type.registerNamespace('AjaxControlToolkit')
Hi, I am new to the AJAX Control Toolkit.  I just downloaded the extensions and toolkit. I followed the instruction to create a 'ASP.NET AJAX Control Project' and was able to test the ConfirmButton template.   However, I want to test the toolkit in a non AJAX Control Project b/c I want to use it on an existing web site. So I created a new 'ASP.NET Web Site' instead and it failed.  I got "The control with ID 'ConfirmButtonExtender1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.&quo...

Sys.ArgumentTypeException: Object of type 'String' cannot be converted to type 'Function'
Hello, Sys.ArgumentTypeException:  Object of type 'String' cannot be converted to type 'Function' This just started happening today after I applied some Updates for Vista Ultimate.  Same code on production does NOT produce this javascript error.  Those servers are Server 2003 R2.  I applied the patches on this page http://arstechnica.com/news.ars/post/20071003-more-performance-updates-fixes-for-vista-released-in-advance-of-sp1.html NOTE - not the SP1 Beta, just the 5 patches to fix various issues. This is happening on any page with a callout extend...

Object of type 'System.Boolean' cannot be converted to type 'System.Int16'.
I have a Checkbox on a detailsview bound to a small int field in my database table.It binds fine when showing the item template on the detailsview, but when I try do an insert/update it blows up with that error.Surely I can bind a checkbox to an integer field, so that unchecked translates to 0, and checked translates to 1?The reason I use a smallint, is its future-proof.  If we decided to switch to a status instead off/on in the future, there are less changes required.  As long as 0 is False and any other value is considered True you should be able to bind the value like this: C...

Object of type 'System.DBNull' cannot be converted to type 'System.DateTime'.
Hi, How can I pass null values to a system.datetime? Thanks in advance for the help J   Below is my code:   Public Class Courses     Public Sub Update_Class(ByVal ClassId As Integer, _    ByVal StatusId As Integer, _    ByVal ClassNumber As Integer, _    ByVal TeacherId As Integer, _    ByVal AmountofParticipants As Integer, _    ByVal CourseDate1 As DateTime, _    ByVal CourseDate2 As DateTime, _    ByVal CourseDate3 As DateTime)     Dim myConnection As New SqlConnection(Conn...

Web resources about - Cannot convert type 'type' to 'type' - asp.net.getting-started

Resources last updated: 2/5/2016 1:17:58 PM