views:

133

answers:

4

I have the below error message in my asp.net website when i replaced the textbox and put dropdown and named the dropdown id same as textbox id.

The value from the drop down should be taken and put in a email body and will be received as mail when i click on the submit button.

Below is the error i am getting when i click on the submit button.

System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.DropDownList' to type 'System.Web.UI.WebControls.TextBox'. at WebApplication1._Default.collectEmailBodyText() in C:\v1.5_production_05June09\Default.aspx.vb:line 213

Please help me !

+1  A: 

How did you replace the dropdown? Sounds to me like your designer file is probably out of sync with your .aspx file. One of them is declaring it as a drop down list, and one of them has typed the control as a textbox.

Check to make sure that your designer.vb file is declaring the control as a dropdownlist instead of a textbox.

womp
A: 

In the code behind you have something doing a FindControl or similar where it is doing a cast.

You can do a ctrl+f find in current document for CType and should find it.

Jonathan
This is the only line i seen when i do a find for CType Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)
A: 

Hi Jaison,

Could you post some of your code so we can look at what the problem might be? Thanks

CalebHC
A: 

It sounds like the code was not recompiled once the change was made or that if it was recompiled that the change was not picked up by the designer file.

the designer file has references to each control placed on the ASPX page, so it will have some line like

protected global::System.Web.UI.WebControls.TextBox myInput

when you chage it to a drop down list, the designer should change to:

protected global::System.Web.UI.WebControls.DropDownList myInput

If this didn't happen you will run into errors. At run time, the controls on the ASPX page are instantiated but if the underlying type differes then you will get an error as soon as you try to access the control.

James Conigliaro
Yes there was two lines one for dropdown and one for textboxi removed the line for textbox now i am getting the following errorSystem.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.DropDownList' to type 'System.Web.UI.WebControls.TextBox'. at WebApplication1._Default.collectEmailBodyText() in C:\v1.5_production_05June09\Default.aspx.vb:line 213