CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

这里怎样才能查找到 MyUserControl 中的 MyButton ?

楼主chjlcn(http://www.chenjiliang.com)2006-03-09 11:46:25 在 .NET技术 / ASP.NET 提问

// 这里怎样才能查找到 MyUserControl   中的 MyButton ?  
  //     我不想要用在MyUserControl公开属性的方法取得,只想用MyButton的ID即"MyButton"取得,行吗?  
   
  MyUserControl.ascx  
   
  <%@   Control   Language="C#"   AutoEventWireup="true"   CodeFile="MyUserControl.ascx.cs"   Inherits="MyControl_MyUserControl"   %>  
  <asp:Button   ID="MyButton"   runat="server"   Text="Button"   />  
   
   
  --------------------------------------------------------------------------------  
   
  TestFindControlInAscx.aspx  
   
  <%@   Page   Language="C#"   AutoEventWireup="true"   CodeFile="TestFindControlInAscx.aspx.cs"   Inherits="Test_TestFindControlInAscx"   %>  
   
  <%@   Register   Src="../MyControl/MyUserControl.ascx"   TagName="MyUserControl"   TagPrefix="uc1"   %>  
   
  <!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
   
  <html   xmlns="http://www.w3.org/1999/xhtml"   >  
  <head   runat="server">  
          <title>无标题页</title>  
  </head>  
  <body>  
          <form   id="form1"   runat="server">  
          <div>  
           
          </div>  
                  <uc1:MyUserControl   ID="MyUserControl1"   runat="server"   />  
          </form>  
  </body>  
  </html>  
   
   
  --------------------------------------------------------------------------------  
  TestFindControlInAscx.aspx.cs  
   
  public   partial   class   Test_TestFindControlInAscx   :   System.Web.UI.Page  
  {  
          protected   void   Page_Load(object   sender,   EventArgs   e)  
          {  
   
  // 这里怎样才能查找到 MyUserControl   中的 MyButton ?  
  //     我不想要用在MyUserControl公开属性的方法取得,只想用MyButton的ID即"MyButton"取得,行吗?  
  Button   button   =   (Button)this.FindControl("MyButton");  
                  if   (button   ==   null)  
                  {  
                          foreach   (Control     control   in   Page.Controls)  
                          {  
   
                                  button   =   (Button)control.FindControl("MyButton");  
                                  if   (button   !=   null)  
                                          break;  
                          }  
                  }  
                  button.Text   =   "我的按钮在Page_Load中修改";  
  }  
  }  
   
  没分可给了,明天再加分。 问题点数:5、回复次数:3Top

1 楼chjlcn(http://www.chenjiliang.com)回复于 2006-03-09 11:47:57 得分 0

我的Page_Load中的代码是不行的,有其他方法吗一?谢谢。Top

2 楼beiouwolf(beiouwolf)回复于 2006-03-09 11:49:48 得分 5

myUserControl.findcontrol()  
   
  不是THIS.  
   
  Top

3 楼chjlcn(http://www.chenjiliang.com)回复于 2006-03-09 11:53:51 得分 0

好的谢谢。不过暂时没分给啊。不好意思。Top

相关问题

  • 查找
  • 如何才能方便的查找jdk中的函数?解决就马上给分。
  • 怎么才能使主窗体文字被选中,而查找窗体不被最小化?????
  • 用findfirst查找文件怎样才能让它得到的结果 按文件名排列的呢??
  • 查找路径!
  • 查找问题
  • 查找文件
  • 条件查找?
  • 三分查找
  • 有关查找?

关键词

得分解答快速导航

  • 帖主:chjlcn
  • beiouwolf

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo