【问题标题】:Find a panel in a asp page with panel id在具有面板 id 的 asp 页面中查找面板
【发布时间】:2014-10-08 04:49:20
【问题描述】:

在我的应用程序中,我从数据库中获取面板 ID,在网页中我需要找到具有该 ID 的面板,我需要使其可见为假。 后面的代码是

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Try
            Dim kioskxml As String = "pnlfindid"
            Dim myControl1 As Control = Page.FindControl(kioskxml)
            If (Not myControl1 Is Nothing) Then
                myControl1.Visible = False

            End If


        Catch ex As Exception

        End Try
    End Sub

但是通过上面的代码 sn-p,我无法获取面板,但它可以很好地与文本框等控件一起使用。 我需要一种在页面加载时找到带有 id 的面板的方法

我的 HTML 页面

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </ajaxToolkit:ToolkitScriptManager>
    <div onload="disableBackButton();">
    <table align="center" width="100%" cellpadding="0" cellspacing="0">
    <tr>
    <td>

        <asp:Panel ID="pnlfindId" runat="server">
          <table align="center" width="100%" cellpadding="0" cellspacing="0">
             <tr>
                <td> 
                <asp:Panel ID="pane3" runat="server">
                </asp:Panel>
                     </td>

                    </tr>


                 </table>

                   </asp:Panel>
             </td>

       </tr>


  </table>

     </asp:Content>

谢谢

【问题讨论】:

  • 确保页面中存在pannelID。
  • ya panelId 在页面中仍然存在 mycontrol 在上下文中什么都没有
  • @AravindGoud 这个面板是动态生成的吗?
  • 可能该控件位于其他控件中,您应该使用递归检索它。如果你愿意,我可以给你看一些 C# 代码。
  • 页面中没有面板我需要找到面板并使其可见 false @Tushar Gupta

标签: c# asp.net vb.net


【解决方案1】:

也许你需要

Dim myControl1 As Control = Master.FindControl(kioskxml)

或

Dim myControl1 As Control = ContentPlaceHolder1.FindControl(kioskxml)

其他一切看起来都很好......

【讨论】:

    【解决方案2】:

    试试这个代码

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        Try
    
                Dim myControl1 As Control =directcast(Page.FindControl("pnlfindid"),Control)
                If (Not myControl1 Is Nothing) Then
                    myControl1.Visible = False
    
                End If
    
    
            Catch ex As Exception
    
            End Try
        End Sub
    

    【讨论】:

      【解决方案3】:

      我假设您试图在内容页面的加载事件中找到控件,而不是母版页的加载事件。

      您需要先找到 contentplaceholder,然后在 contentplaceholder 中找到面板 由于我不熟悉 VB.NET 语法,所以我提供 C# 语法:

      ContentPlaceHolder cont = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
      Panel myPanel = cont.FindControl(kioskxml); 
      

      当然,否则,如果您在母版页的页面加载事件中执行此操作,

       ContentPlaceHolder cont = (ContentPlaceHolder)this.FindControl("ContentPlaceHolder1");
       Panel myPanel = cont.FindControl(kioskxml); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-18
        • 1970-01-01
        • 2013-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多