2009-06-09 6 views
0

J'ai le message d'erreur ci-dessous sur mon site Web asp.net lorsque j'ai remplacé la zone de texte et placé la liste déroulante et nommé l'ID déroulant comme ID de zone de texte.Problème de moulage de type dans le code derrière le fichier

La valeur de la liste déroulante devrait être prise et placée dans un corps de courrier électronique et sera reçue comme courrier quand je clique sur le bouton soumettre.

Ci-dessous l'erreur que je reçois lorsque je clique sur le bouton Soumettre.

System.InvalidCastException: impossible à jeter objet de type 'System.Web.UI.WebControls.DropDownList' de type 'System.Web.UI.WebControls.TextBox. à WebApplication1._Default.collectEmailBodyText() dans C: \ v1.5_production_05June09 \ Default.aspx.vb: ligne 213

Mon code derrière le fichier est le suivant:

''//------------------------------------------------------------------------------ 
''// <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 

S'il vous plaît aidez-moi!

+0

Ceci est la partie _designer_generated de votre code derrière. Nous n'avons pas vraiment besoin de voir le tout, et nous demander de réparer votre bug sans au moins le nettoyer un peu est très impoli. –

Répondre

0

Dans votre code derrière, il semble que dans vos FindControls vous essayez de gérer un DropDownList comme un TextBox. Vous devez vérifier que les définitions d'objets dans votre fichier .aspx et votre code correspondent dans leurs déclarations et dans FindControls.

+0

Pourriez-vous expliquer comment faire cela? –

+0

Eh bien, par exemple, si dans votre page .aspx vous avez les objets suivants définis: Puis dans le code derrière vous voudriez des déclarations qui sont correctes selon les types d'objet: protected DropDownList SomeDropDown; protected TextBox SomeTextBox; Dans votre méthode FindControls, vous voudriez quelque chose comme: SomeDropDown = (DropDownList) this.Master.FindControl ("ContentBody"). FindControl ("SomeDropDown"); SomeTextBox = (TextBox) this.Master.FindControl ("ContentBody"). FindControl ("SomeTextBox"); –

+0

Oui ceci est mon code ci-dessous quelque chose de mal tempPanelLabel = form1.FindControl ("lbl_" + panelUsed + "_label" + counter.ToString()) tempPanelInputBox = form1.FindControl ("txt_" _INPUT + panelUsed + » "+ counter.ToString()) –

0

je chercherais le contrôle dans le fichier code-behind et changer le:

Global.System.Web.UI.WebControls.TextBox 

Pour:

Global.System.Web.UI.WebControls.DropDownList 

Quel est le nom du contrôle?

+0

lbl_panview3_label1 –

+0

Ce n'est pas un dropdownlist ou une zone de texte Ai-je raté quelque chose? – orandov

+0

désolé son txt_panview3_input1 –

Questions connexes