代码之家  ›  专栏  ›  技术社区  ›  Cheng Chen

我的验证器在哪里?

  •  1
  • Cheng Chen  · 技术社区  · 15 年前

    我的页面中有一个验证程序:

    <asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="IdentifySEDSED1TxtDate" ErrorMessage="Significant Event Date 1 is missing" ValidType="SEDate">*</asp:RequiredFieldValidator>
    

    我在Page_Load中发现:(下面是手表窗口的屏幕截图)

    this.FindControl("rfv1")    {Text = "*"}    
    
    rfv1    The name 'rfv1' does not exist in the current context
    

    看,我可以用FindControl获得这个控件,但我不能直接用ID获得它!会发生什么?

    1 回复  |  直到 15 年前
        1
  •  0
  •   VoodooChild    15 年前

    如果要在页面上查找面板,则需要在页面的表单中查找它们,因为面板放置在表单中,而不是直接放置在页面上。

    至少我认为这就是问题所在。。。。

    这是否有效:

    this.Form.FindControl(rfv1);