在内容页面内查找控件
我在母版页中使用以下代码来查找内容页面内的控件。在第一页加载时,它工作正常;但是,当我从内容页面上的下拉列表中选择一个项目并且启用了自动回发时,我收到错误“对象引用未设置到对象的实例”。这意味着 FindControl() 函数无法找到内容页面内的控件。出现这个问题的原因是什么?
PlaceHolder pHolder = (PlaceHolder)ContentPlaceHolder2.FindControl("PlaceHolder1");
Label lblPage = (Label)pHolder.FindControl("lblPageName");
if (lblPage.Text == "DesignSerachSQGrid")
{
}
编辑...
下拉列表的 HTML 代码:
<telerik:RadComboBox ID="ddlSearchL1" runat="server" Width="400px" Skin="Office2007"
onselectedindexchanged="ddlSearchL1_SelectedIndexChanged"
AutoPostBack="True" Font-Names="Eras Medium ITC" Font-Size="X-Small"
onprerender="ddlSearchL1_PreRender">
<Items>
<telerik:RadComboBoxItem runat="server" Text="Please Select ................"
Value="Please Select ................" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Design Documents"
Value="Design Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Vendor Documents"
Value="Vendor Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Business Documents"
Value="Business Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Management Documents"
Value="Management Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Squad Check - Management"
Value="Squad Check - Management" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Transmittal - Management"
Value="Transmittal - Management" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Transmittal - Design"
Value="Transmittal - Design" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Squad Check - Design"
Value="Squad Check - Design" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Transmittal - Vendor"
Value="Transmittal - Vendor" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Squad Check - Vendor"
Value="Squad Check - Vendor" Font-Name="Eras Medium ITC" />
</Items>
</telerik:RadComboBox>
I'm using the following code in my master page to find controls inside content pages. On the first page load, it works fine; but when i select an item from a dropdown which is on content page and it autopostback is enabled, then i'm getting the error "object reference not set to an instance of a object". This means the FindControl() function was unable to find the controls inside content pages. What is the reason for this issue?
PlaceHolder pHolder = (PlaceHolder)ContentPlaceHolder2.FindControl("PlaceHolder1");
Label lblPage = (Label)pHolder.FindControl("lblPageName");
if (lblPage.Text == "DesignSerachSQGrid")
{
}
edit...
Html code for the dropdown:
<telerik:RadComboBox ID="ddlSearchL1" runat="server" Width="400px" Skin="Office2007"
onselectedindexchanged="ddlSearchL1_SelectedIndexChanged"
AutoPostBack="True" Font-Names="Eras Medium ITC" Font-Size="X-Small"
onprerender="ddlSearchL1_PreRender">
<Items>
<telerik:RadComboBoxItem runat="server" Text="Please Select ................"
Value="Please Select ................" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Design Documents"
Value="Design Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Vendor Documents"
Value="Vendor Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Business Documents"
Value="Business Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Management Documents"
Value="Management Documents" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Squad Check - Management"
Value="Squad Check - Management" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Transmittal - Management"
Value="Transmittal - Management" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Transmittal - Design"
Value="Transmittal - Design" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Squad Check - Design"
Value="Squad Check - Design" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Transmittal - Vendor"
Value="Transmittal - Vendor" Font-Name="Eras Medium ITC" />
<telerik:RadComboBoxItem runat="server" Text="Squad Check - Vendor"
Value="Squad Check - Vendor" Font-Name="Eras Medium ITC" />
</Items>
</telerik:RadComboBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看这篇文章: ASP .NET 2.0 MasterPages 和 FindControl()
使用它
You can check this post : ASP.NET 2.0 MasterPages and FindControl()
use it