Jaison
Jaison

Reputation:

Error when i change the textbox to dropdown

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 !

Upvotes: 0

Views: 344

Answers (3)

James Conigliaro
James Conigliaro

Reputation: 3827

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.

Upvotes: 0

Jonathan
Jonathan

Reputation: 1892

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.

Upvotes: 0

womp
womp

Reputation: 116987

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.

Upvotes: 1

Related Questions