在我的应用程序中,我从数据库中获取面板ID,在网页中,我需要找到具有该ID的面板,我需要将其显示为false。 代码背后是
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
但是通过上面的代码片段,我无法获取面板,但它可以与文本框等控件一起使用。 我需要一种方法来查找页面加载时带有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>
由于
答案 0 :(得分:1)
也许你需要
Dim myControl1 As Control = Master.FindControl(kioskxml)
或
Dim myControl1 As Control = ContentPlaceHolder1.FindControl(kioskxml)
其他一切看起来都很好......
答案 1 :(得分:1)
试用此代码
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
答案 2 :(得分:0)
我假设您正在尝试在内容页面的加载事件中找到控件,而不是母版页的加载事件。
您需要先找到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);