[英]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.