使用的FindControl()来查找控制 [英] Using FindControl() to find control
本文介绍了使用的FindControl()来查找控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我试图找到这样我就可以插入文本到它文字
控制。我有一个包含多个内容占位符母版页。
I have a Literal
control that I am trying to locate so I can insert text into it. I have a Master page that contains several content placeholders.
<asp:Content ID="Content7" ContentPlaceHolderID="MainLinks" runat="server">
<h3>Project Navigation</h3>
<ul class="rightColBoxNav">
<asp:Literal ID="litNavLinks" runat="server" />
</ul>
</asp:Content>
我不断收到对象引用不设置到对象的实例。如何找到这个对象,所以我可以查找和更新呢?
I keep getting "Object reference not set to an instance of an object." How do I locate this object so I can find and update it?
我曾尝试:
((Literal)Page.FindControl("litNavLinks")).Text = sb.ToString();
((Literal)Page.Page.FindControl("litNavLinks")).Text = sb.ToString();
((Literal)Page.FindControl("Content7").FindControl("litNavLinks")).Text = sb.ToString();
无济于事。如何确定的位置?
to no avail. How do I determine the location?
推荐答案
从母版中:
var literal = (Literal)FindControl("MainLinks").FindControl("litNavLinks");
literal.Text = sb.ToString();
从视图中:
litNavLinks.Text = sb.ToString();
这篇关于使用的FindControl()来查找控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文