在MasterPage中包含的Aspx中查找UserControl控件 [英] Find UserControl Controls in Aspx included in MasterPage
问题描述
你好,
如何访问位于aspx页面中且包含在母版页中的用户控件的控件.....
谢谢
Hello,
How to access the control of a user control which is in a aspx page and that is included in with Master Page.....
Thank You
推荐答案
看看:
// Gets a reference to a TextBox control inside a ContentPlaceHolder
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
mpContentPlaceHolder =
(ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if(mpContentPlaceHolder != null)
{
mpTextBox = (TextBox) mpContentPlaceHolder.FindControl("TextBox1");
if(mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
}
// Gets a reference to a Label control that is not in a
// ContentPlaceHolder control
Label mpLabel = (Label) Master.FindControl("masterPageLabel");
if(mpLabel != null)
{
Label1.Text = "Master page label = " + mpLabel.Text;
}
来自: MSDN [如何在ASP.Net页的MasterPage ContentPlaceHolder内部查找控件 [^ ]
内部母版页 [用户控件以及JavaScript和母版页 [
From: MSDN[^]
Also have a look:
How To Find Controls Inside MasterPage ContentPlaceHolder Of ASP.Net Page[^]
Inside Master Pages[^]
Similar QA:
User Controls and JavaScript and Master Pages[^]
Check below link
^ ]
http://www.techtasks.net/2011/03/how-to-find-controles-inside-masterpage.html[^]
为什么 ^ ]?
以及为什么要寻找代码?你这边没努力吗?
Why repost[^]?
And why do you seek for code? No effort from your side?
// define this as a property in your usercontrol
public Button MySubmitButton
{
get{return mySubmitButton;}
}
访问usercontrol的此属性,并根据需要设置它的属性.
旧参考: http://msdn.microsoft.com/en-us /library/wt9d35z6%28v=vs.71%29.aspx [
Access this property of usercontrol and set the properties of it as per your need.
Old reference: http://msdn.microsoft.com/en-us/library/wt9d35z6%28v=vs.71%29.aspx[^]
Try out, post specific issue.
这篇关于在MasterPage中包含的Aspx中查找UserControl控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!