我有个a.aspx的窗体页面,里面只放了一个a.ascx的用户控件
a.ascx内只有一个label1的控件请问如何在a.aspx的代码里访问这个label1的子控件
比如在a.aspx的Page_load事件(或其他事件)直接给a.ascx的label1控件赋值?如label1.Text="xxxx"
可以这样吗?
a.ascx内只有一个label1的控件请问如何在a.aspx的代码里访问这个label1的子控件
比如在a.aspx的Page_load事件(或其他事件)直接给a.ascx的label1控件赋值?如label1.Text="xxxx"
可以这样吗?
将protected 改为public.
(Label)a.FindControl("label1")
Dim NewLabel As New a
NewLabel .label1.Text = "Test"
不行呀,没反映~~
wang790809(石头)
你的代码我看的不是很明白,能否给出VB的格式?晕,要是这个问题搞不定的话,那这些用户控件还怎么重用呀?
各位帮我看看呀
将protected 改为public.ctype(a.FindControl("label1"),Label).text = "哈哈";
然后你不就可以对newLabel做操做了吗
jyk(喜欢编程。和气生财。共同提高。共同进步)
用的你的方法
Dim a As New tests
CType(a.FindControl("lab"), Label).Text = "哈哈"
结果:异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 26: Dim a As New tests
行 27: CType(a.FindControl("lab"), Label).Text = "哈哈" (出错行)
============================================================================
renyu732(Good Good Study,Day Day Up.) 、
你的也不行呀
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 28: Dim NewLabel As Label = CType(a.FindControl("lab"), Label)
行 29: NewLabel.Text = "test" (出错行)
===========================================================================各位帮帮忙呀,帮看看怎么实现呀
谁要分我给他
public labeltext
labeltext=label1.text然后在a.aspx里以用户控件属性的方式改变labeltext的值,,,,
<uc1:mycontrol runat="server" labeltext="hello"></uc1:mycontrol>还可以用
get
set
你的这个方法我知道,但页面一但输入框和选择框达到几十或者上百的话,那这么做还不累死?
而且动态调用的时候还需要对页面绑定~
有简单的方法吗?
{
myControl1 = this.FindControl("WebUserControl11"); // 在此处放置用户代码以初始化页面
}
private void Button1_Click(object sender, System.EventArgs e)
{
myControl1.Visible = true;
UserControl myUserControl = (UserControl)myControl1;
Label uLabel1 = (Label)myUserControl.FindControl("Label1");
Label1.Text = "控件内容:" + uLabel1.Text;
}
private Control myControl1 =null;
不过你的代码是C#的,我看不明白
可否换成等价的VB语法呢?
非常感谢^_^