FindControl错误 [英] FindControl ERROR

查看:126
本文介绍了FindControl错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要以CUW步骤存储其他用户信息

need to store additional userinfo in CUW steps

//register.aspx

//register.aspx

         <p>
         <b>HomeTown:</b><br /> <asp:TextBox ID = "HomeTown" runat ="server"></asp:TextBox>
         </p>
         <p>
         <b>HomepageUrl:</b><br /> <asp:TextBox ID = "HomepageUrl" runat ="server"></asp:TextBox>
         </p>
         <p>
         <b>Signature:</b><br /> <asp:TextBox ID = "Signature" runat ="server"></asp:TextBox>
         </p>
         </asp:WizardStep>
         <asp:CompleteWizardStep runat="server" />
      </WizardSteps>
   </asp:CreateUserWizard>

//THIS是背后代码的一部分WizardStep UserSettings = NewUserWizard.FindControl("UserSettings")作为WizardStep;

//THIS is part of code behind WizardStep UserSettings = NewUserWizard.FindControl("UserSettings") as WizardStep;

     // Programmatically reference the TextBox controls
     TextBox HomeTown = UserSettings.FindControl("HomeTown") as TextBox;...ERROR Object reference not set to an instance of an object. 

感谢帮助

推荐答案

您很有可能已经找到了该问题的答案或继续前进,但是我在自己的搜索中发现了这个问题,并以为我d为可能正在搜索的其他任何人提供答案.

There is a good chance you've already found an answer to this question or have moved on, but I found this question in my own search and thought I'd provide an answer for anyone else who might be searching.

上面的示例的问题(除了顶部缺少的代码(告诉我您的步骤的ID是什么))是您需要在向导的每个步骤中分别查找控件.因此,如果您在向导的第一步中正在寻找超链接,那么它将找到它:

The problem with the sample above (besides the code that is missing at the top that would tell me what the ID of your step) is that you need to look for controls in each of the steps of the wizard individually. So, if you were looking for a hyperlink in the first step of your wizard then this would find it:

TextBox HomeTown = (TextBox)UserSettings.WizardSteps[0].FindControl("HomeTown");

如果您不希望带有HomeTown文本框的步骤始终是集合中的第一步,那么它将起作用:

If you didn't want to presume that the step with the HomeTown text box would always be the first step in the collection, this would work:

WizardStep wizStep (WizardStep)wizSample.FindControl("SampleStepName");
TextBox HomeTown = (TextBox)wizStep.FindControl("HomeTown");

在我的情况下,我要查找的控件在TemplatedWizardStep中,因此我必须使用以下代码:

In my case, the control I was looking for was in a TemplatedWizardStep, so I had to use the following code:

TemplatedWizardStep wizStep = (TemplatedWizardStep)wizSample.FindControl("SampleStepName");
Panel pnlSample =(Panel)wizStep.ContentTemplateContainer.FindControl("pnlSample");
pnlSample .Visible = true;


注意:我使用的是Wizard类,因为CreateUserWizard类是基于Wizard的,所以我认为上面的代码对两者都适用.


Note: I was using the Wizard class, because the CreateUserWizard class is based on the Wizard I presume that the code above would work for both.

这篇关于FindControl错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆