in general, if you need to modify an internal control's property, you should expose the control to the publicfor example, in B, you would addpublic TextBox MyTextBox
{
  get { return TextBox1;}
}then you would do B1.MyTextBox.Text = "123";or use a string propertypublic String MyText
{
  get { return TextBox1.Text;}
  set { TextBox1.Text = value;}
}but as a hack, if you are sure TextBox1 is properly created in B and has an ID of "TextBo1",  you can try something likeTextBox t = (TextBox) B1.FindControl("TextBox1");
>>>在网页(ASPX中)又如何访问自定义控件中的服务器控件(如: ImageButton 或 TextBox等) 并修改其属性与得到其事件响应?<%@ Register TagPrefix="cc" Namespace="YourCustomControlNameSpace" ... %><cc:YourCustomCOntrolClassName id="YourCustomControlID" runat="server" ... />you should declare the control in codebehindprotected YourCustomControlNameSpace.YourCustomCOntrolClassName YourCustomControlID;thenYourCustomControlID.Property1 = "abc";
YourCustomControlID.EventName += new EventHandler(YourEventHandler);

解决方案 »

  1.   

    好运气啊,得到 saucer(思归/MVP) 老大的帮助。
      

  2.   

    多谢 saucer(思归/MVP) 老大.
    我在A控件的代码段中这样引用
      B1.MyTextBox.Text = "123";或
      TextBox t = (TextBox) B1.FindControl("TextBox1"); 皆出错, 无法找到 B1 ?   在A控件中已用拖动方式加入 B 控件且其ID为 B1, 为何不能引用.
    请指教   急呀!
      

  3.   

    where is your code? code behind? did you see a declaration likeprotected YourNS.YourClass B1;???post more code
      

  4.   

    好, 这是A控件
    namespace NewGLYX.Person
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Configuration;
    using System.Data.SqlClient; /// <summary>
    /// PersonWorkChangeCon 的摘要说明。
    /// </summary>
    public class PersonWorkChangeCon : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.TextBox NameToSeek;
    protected System.Web.UI.WebControls.TextBox EngNameToSeek;
    protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
    protected System.Web.UI.WebControls.TextBox Name;
    protected System.Web.UI.WebControls.TextBox WorChangeDate;
    protected System.Web.UI.WebControls.DropDownList DeparmentOld;
    protected System.Web.UI.WebControls.DropDownList BusinessOld;
    protected System.Web.UI.WebControls.TextBox ChangeNote;
    protected System.Web.UI.WebControls.DropDownList DeparmentNew;
    protected System.Web.UI.WebControls.ImageButton Seek;
    protected System.Web.UI.WebControls.ImageButton IntroReport;
    protected System.Web.UI.WebControls.ImageButton AddChange;
    protected System.Web.UI.WebControls.DropDownList BusinessNew; private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.Seek.Click += new System.Web.UI.ImageClickEventHandler(this.Seek_Click);
    this.AddChange.Click += new System.Web.UI.ImageClickEventHandler(this.AddChange_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Seek_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {


    // 搜索定位, 查询是否存在此人 SqlConnection myConnection = new SqlConnection( ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand myCommand= new SqlCommand("Seek_Person",myConnection);
    myCommand.CommandType=CommandType.StoredProcedure; SqlParameter ParameterName=new SqlParameter("@姓名_1",SqlDbType.VarChar);
    ParameterName.Value=NameToSeek.Text;
    myCommand.Parameters.Add(ParameterName); SqlParameter ParameterEnglishName=new SqlParameter("@英文名_2",SqlDbType.VarChar);
    ParameterEnglishName.Value=EngNameToSeek.Text;
    myCommand.Parameters.Add(ParameterEnglishName); SqlParameter ParameterReturn=new SqlParameter("@姓名_3",SqlDbType.VarChar,12);
    ParameterReturn.Direction =ParameterDirection.Output;
    myCommand.Parameters.Add(ParameterReturn); myConnection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close(); if (ParameterReturn.Value.ToString()!="") 
    {
      AddChange.Visible=true;
                  IntroReport.Visible=true;              Name.Text=ParameterReturn.Value.ToString();
     
    }
    else
    {
       AddChange.Visible=false;
       IntroReport.Visible=false;    Name.Text="";
      //Response.Write("<br>alert("查无此人")<br>");
    }
      } private void AddChange_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    // SqlConnection myConnection = new SqlConnection( ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlCommand myCommand= new SqlCommand("insert_PersonWorkChange",myConnection);
    myCommand.CommandType=CommandType.StoredProcedure;
    SqlParameter ParameterName=new SqlParameter("@姓名_1",SqlDbType.VarChar,50);
    ParameterName.Value=Name.Text;
    myCommand.Parameters.Add(ParameterName); SqlParameter ParameterEnglishName=new SqlParameter("@英文名_2",SqlDbType.VarChar,50);
    ParameterEnglishName.Value=EngNameToSeek.Text;
    myCommand.Parameters.Add(ParameterEnglishName); SqlParameter ParameterChangeDate=new SqlParameter("@变动时间_3",SqlDbType.VarChar,50);
    ParameterChangeDate.Value=WorChangeDate.Text;
    myCommand.Parameters.Add(ParameterChangeDate); SqlParameter ParameterDeparmentOld=new SqlParameter("@原部门_4",SqlDbType.VarChar,50);
    ParameterDeparmentOld.Value=DeparmentOld.SelectedValue.ToString();
    myCommand.Parameters.Add(ParameterDeparmentOld); SqlParameter ParameterDeparmentNew=new SqlParameter("@新部门_5",SqlDbType.VarChar,50);
    ParameterDeparmentNew.Value=DeparmentNew.SelectedValue.ToString();
    myCommand.Parameters.Add(ParameterDeparmentNew); SqlParameter ParameterBusinessOld=new SqlParameter("@原职务_6",SqlDbType.VarChar,50);
    ParameterBusinessOld.Value=BusinessOld.SelectedValue.ToString();
    myCommand.Parameters.Add(ParameterBusinessOld); SqlParameter ParameterBusinessNew=new SqlParameter("@新职务_7",SqlDbType.VarChar,50);
    ParameterBusinessNew.Value=BusinessNew.SelectedValue.ToString();
    myCommand.Parameters.Add(ParameterBusinessNew); SqlParameter ParameterNote=new SqlParameter("@备注_8",SqlDbType.VarChar,50);
    ParameterNote.Value=ChangeNote.Text;
    myCommand.Parameters.Add(ParameterNote); myConnection.Open();
    myCommand.ExecuteNonQuery();
    myConnection.Close();           //----------------------  Give then Prompt  ------------------------------------------------
                 }
    }
    }
      

  5.   

    这种B控件:
    namespace NewGLYX
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls; /// <summary>
    /// RightPrompt 的摘要说明。
    /// </summary>
    public class RightPrompt : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.ImageButton PromptInfor;
    protected System.Web.UI.WebControls.ImageButton ImageButton2;
    protected System.Web.UI.WebControls.ImageButton ImageButton3;
    protected System.Web.UI.WebControls.HyperLink HyperLink1;
    protected System.Web.UI.WebControls.HyperLink HyperLink2;
    protected System.Web.UI.WebControls.TextBox Information;
    protected System.Web.UI.WebControls.TextBox TextBox2; public ImageButton MyPromptInfor
    {
    get { return PromptInfor;}

    } public string MyPromptInforImgUrl
    {
    get { return PromptInfor.ImageUrl.ToString(); }
    set { PromptInfor.ImageUrl=value; }
    } private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }
      

  6.   

    老大好, 下面是HTMLB控件:
    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="RightPrompt.ascx.cs" Inherits="NewGLYX.RightPrompt" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <LINK href="GLYXForm.css" type="text/css" rel="stylesheet">
    <FONT face="宋体"></FONT><FONT face="宋体"></FONT>
    <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="180" bgColor="whitesmoke" border="0">
    <TR>
    <TD width="10"></TD>
    <TD width="32"><FONT face="宋体"></FONT></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32">
    <asp:ImageButton id="PromptInfor" runat="server" ImageUrl=".\Images\PromptInformation.gif"></asp:ImageButton></TD>
    <TD><FONT face="宋体"></FONT></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32" colSpan="2"><FONT face="宋体">
    <asp:TextBox id="Information" BorderWidth="0px" BackColor="WhiteSmoke" Width="160px" Height="150px"
    runat="server" BorderColor="White" CssClass="PromptInformation"></asp:TextBox></FONT></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32"></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32">
    <asp:ImageButton id="ImageButton2" runat="server" ImageUrl=".\Images\PromptSafeAlert.gif" Visible="False"></asp:ImageButton></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32"><FONT face="宋体">
    <asp:TextBox id="TextBox2" BorderWidth="0px" BackColor="WhiteSmoke" Width="160px" Height="150px"
    runat="server" BorderColor="White" CssClass="PromptAlert"></asp:TextBox></FONT></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32"></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32">
    <asp:ImageButton id="ImageButton3" runat="server" ImageUrl=".\Images\PromptHelpReady.gif" Visible="False"></asp:ImageButton></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32"><FONT face="宋体">
    <asp:HyperLink id="HyperLink1" Width="128px" runat="server" Font-Size="Smaller" CssClass="PrompHelp"
    Visible="False">帮助系统</asp:HyperLink></FONT></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10"></TD>
    <TD width="32"><FONT face="宋体">
    <asp:HyperLink id="HyperLink2" Width="136px" runat="server" Font-Size="Smaller" CssClass="PrompHelp"
    Visible="False">桂林小草软件有限公司</asp:HyperLink></FONT></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD width="10" height="100%"><FONT face="宋体"></FONT></TD>
    <TD width="32" height="100%"></TD>
    <TD height="100%"></TD>
    </TR>
    <TR>
    <TD width="10" height="100%"><FONT face="宋体"></FONT></TD>
    <TD width="32" height="100%"></TD>
    <TD height="100%"></TD>
    </TR>
    </TABLE>