简体   繁体   中英

Find a panel in a asp page with panel id

in my app i fetch the panel id from database and in webpage i need to find the panel with that id i need to make it visible false. code behind is

 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

but by the above code snippet, I cannot fetch the panel but it works fine with controls like textbox and other. I need a way to find the panel with id on page load

My Html Page

<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>

Thanks

Maybe you need

Dim myControl1 As Control = Master.FindControl(kioskxml)

or

Dim myControl1 As Control = ContentPlaceHolder1.FindControl(kioskxml)

everything else looks fine...

Try this Code

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

I am assuming you are trying to find the control in the content pages's load event as opposed to master page's load event.

You will need to first find the contentplaceholder and then find the panel within contentplaceholder As I am not familiar with VB.NET syntax, I am providing C# syntax:

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

Ofcourse, else, if you are doing it on Master page's page load event,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM