简体   繁体   English

C#.Net向导控件删除动态添加的用户控件

[英]C# .Net Wizard control deleting dynamically added user controls

I'm writing a survey web application and I have a wizard control with a few steps added from the designer view. 我正在编写一个调查Web应用程序,并且有一个向导控件,并从设计者视图中添加了几个步骤。 The user selects the name of the survey they would like to complete in the first step, then the user hits the next button and I read the survey details from the database. 用户在第一步中选择要完成的调查的名称,然后单击下一步,然后我从数据库中读取调查详细信息。 I have created custom user controls for each type of question which I programatically add to step 2 of the wizard control after reading each survey question from the database. 我为每种类型的问题创建了自定义用户控件,在从数据库中读取每个调查问题之后,我以编程方式将其添加到向导控件的步骤2中。

This works fine, and the survey displays as expected. 这可以正常工作,并且调查显示按预期方式。 However, when the user fills in the answers to the questions and hits next, I don't have access to the answers typed into the text boxes. 但是,当用户填写问题的答案并单击下一步时,我无权访问在文本框中键入的答案。 It seems as though all the custom controls I have added to step 2 have been deleted since I get a null reference exception when trying to access the controls. 似乎我添加到步骤2的所有自定义控件都已删除,因为在尝试访问控件时收到空引用异常。 I even printed out the number of controls in step 2 after the next button was hit (it should be 11) but instead printed out that there were no controls in the step. 在按下下一个按钮(应该为11)后,我什至在步骤2中打印出控件的数量,但相反,在步骤2中则打印出没有控件。

Am I missing something? 我想念什么吗? Is there a property I need to set to be able to access my dynamically added controls from a step? 我是否需要设置一个属性,以便能够从一个步骤访问动态添加的控件?

You are saying that null reference exception is comming. 您是说空引用异常即将到来。

Try to find if you are using drop down control in your application. 尝试查找您是否在应用程序中使用下拉控件。

If it is present, then this exception comes when there is no selected value in drop down and you try to insert it in database. 如果存在,则当下拉列表中没有选定的值并且您尝试将其插入数据库时​​,将出现此异常。

also check your code if you are writing it as, ddlOptions.SelectedItem.toString(); 如果您是以ddlOptions.SelectedItem.toString();形式编写的,还请检查您的代码ddlOptions.SelectedItem.toString();

If so, then edit it to>> ddlOptions.text 如果是这样,则将其编辑为>> ddlOptions.text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在用户导航期间如何禁用控件时,如何使用c#中的Control.AddAt管理动态添加的asp.net控件 - How to manage dynamically added asp.net controls with Control.AddAt in c# when during user navigation a Control could be disabled 从动态加载的Web用户控件(asp.net C#)中的控件访问值 - Accessing value from the controls within a dynamically loaded web user control (asp.net c#) C#ASP.NET Wrap通过动态添加的Label控件动态添加了CheckBox控件 - C# ASP.NET Wrap dynamically added CheckBox Control with a dynamically added Label Control 用户控件C#向导创建中的错误 - error in user control C# wizard creation 在c#winforms中的控件内水平和垂直对齐动态添加的控件 - Align dynamically added controls horizontally and vertically within a control in c# winforms 如何在C#中动态创建向导控件? - How do I dynamically create a wizard control in c#? 在C#asp.net中动态添加用户控件 - Dynamically adding user control in C# asp.net 如何在C#中保存动态添加的控件 - How to Save Dynamically Added Control in C# 在winform c#.net应用程序中更改动态添加的控件的值,如何跟踪动态添加的控件 - Change values of dynamically added controls in winform c#.net application, how to track dynamically added controls C#中动态创建的用户控件 - Dynamically Created User Controls In C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM