在代码隐藏文件后输入转换问题

时间:2009-06-09 17:50:17

标签: .net asp.net visual-studio-2008

我的asp.net网站上有以下错误消息,当我替换文本框并将下拉列表命名为与文本框ID相同的下拉列表ID时。

下拉菜单中的值应该被记录下来并放入电子邮件正文中,当我点击提交按钮时,它将作为邮件收到。

以下是我点击提交按钮时收到的错误。

  

System.InvalidCastException:无法将类型为“System.Web.UI.WebControls.DropDownList”的对象强制转换为“System.Web.UI.WebControls.TextBox”。在C:\ v1.5_production_05June09 \ Default.aspx.vb中的WebApplication1._Default.collectEmailBodyText():第213行

我的代码隐藏文件如下:

''//------------------------------------------------------------------------------
''// <auto-generated>
''//     This code was generated by a tool.
''//     Runtime Version:2.0.50727.3053
''//
''//     Changes to this file may cause incorrect behavior and will be lost if
''//     the code is regenerated.
''// </auto-generated>
''//------------------------------------------------------------------------------

Option Strict On
Option Explicit On

Partial Public Class _Default

    Protected WithEvents form1 As Global.System.Web.UI.HtmlControls.HtmlForm

    Protected WithEvents MultiView1 As Global.System.Web.UI.WebControls.MultiView

    Protected WithEvents View0 As Global.System.Web.UI.WebControls.View

    Protected WithEvents lbl_viewTitle0 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents lbl_view0_firstName As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_firstName As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents Validator_FirstName As Global.System.Web.UI.WebControls.RequiredFieldValidator

    Protected WithEvents lbl_view0_surname As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txtSurName As Global.System.Web.UI.WebControls.TextBox    

    Protected WithEvents Validator_Surname As Global.System.Web.UI.WebControls.RequiredFieldValidator

    Protected WithEvents lbl_view0_ContactNum As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_contactNum As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents Validator_ContactNumber As Global.System.Web.UI.WebControls.RequiredFieldValidator

    Protected WithEvents lbl_view0_typeOfRequest As Global.System.Web.UI.WebControls.Label

    Protected WithEvents ddl_view0_typeOfRequest As Global.System.Web.UI.WebControls.DropDownList

    Protected WithEvents lbl_view0_workUnitLevel As Global.System.Web.UI.WebControls.Label

    Protected WithEvents ddl_view0_workUnitLevel As Global.System.Web.UI.WebControls.DropDownList

    Protected WithEvents btn_view0_forward As Global.System.Web.UI.WebControls.Button

    Protected WithEvents View1 As Global.System.Web.UI.WebControls.View

    Protected WithEvents lbl_viewTitle1 As Global.System.Web.UI.WebControls.Label  

    Protected WithEvents lbl_view1_firstName As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_view1_firstname As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents lbl_view1_surname As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_view1_surname As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents lbl_view1_userID As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_view1_userID As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents lbl_view1_workUnit As Global.System.Web.UI.WebControls.Label

    Protected WithEvents ddl_view1_workunit As Global.System.Web.UI.WebControls.DropDownList

    Protected WithEvents panview0 As Global.System.Web.UI.WebControls.Panel

    Protected WithEvents lbl_panView0_label1 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_panview0_input1 As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents panview2 As Global.System.Web.UI.WebControls.Panel

    Protected WithEvents lbl_panview2_label1 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_panview2_input1 As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents panview1 As Global.System.Web.UI.WebControls.Panel

    Protected WithEvents lbl_panview1_label1 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_panview1_input1 As Global.System.Web.UI.WebControls.TextBox   

    Protected WithEvents panview3 As Global.System.Web.UI.WebControls.Panel

    Protected WithEvents lbl_panview3_label1 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_panview3_input1 As Global.System.Web.UI.WebControls.DropDownList

    Protected WithEvents lbl_panview3_label2 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_panview3_input2 As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents btn_view1_back As Global.System.Web.UI.WebControls.Button

    Protected WithEvents btn_view1_forward As Global.System.Web.UI.WebControls.Button

    Protected WithEvents View2 As Global.System.Web.UI.WebControls.View

    Protected WithEvents lbl_viewTitle2 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents lbl_view2_ManagersEmailAddress As Global.System.Web.UI.WebControls.Label

    Protected WithEvents txt_view2_ManagersEmailAddress As Global.System.Web.UI.WebControls.TextBox

    Protected WithEvents rfv_view2_managersEmail As Global.System.Web.UI.WebControls.RequiredFieldValidator

    Protected WithEvents rev_view2_managersEmail As Global.System.Web.UI.WebControls.RegularExpressionValidator

    Protected WithEvents btn_view2_back As Global.System.Web.UI.WebControls.Button  

    Protected WithEvents btn_view02_forward As Global.System.Web.UI.WebControls.Button

    Protected WithEvents View3 As Global.System.Web.UI.WebControls.View

    Protected WithEvents lbl_viewTitle3 As Global.System.Web.UI.WebControls.Label

    Protected WithEvents lit_preview As Global.System.Web.UI.WebControls.Literal

    Protected WithEvents btn_view3_submit As Global.System.Web.UI.WebControls.Button

    Protected WithEvents btn_view3_back As Global.System.Web.UI.WebControls.Button
End Class

请帮助我!

2 个答案:

答案 0 :(得分:0)

在你的代码中,看起来你在FindControls中试图将DropDownList作为TextBox处理。您应该验证.aspx中的对象定义和后面的代码对应于它们的声明和FindControls。

答案 1 :(得分:0)

我会在代码隐藏文件中查找控件并更改:

Global.System.Web.UI.WebControls.TextBox

要:

Global.System.Web.UI.WebControls.DropDownList

控件的名称是什么?