同意vzxq(灵感人)说的,
你的TxtZip.Text值是不是为null?
你的address.ascx控件中有TxtZip这个控件吗?

解决方案 »

  1.   

    我的address.ascx控件中有個textbox就是txtzip這個控件啊!!
      

  2.   

    我试了试可以啊,我用的是C#。
    public class MyControl : System.Windows.Forms.UserControl
    {
    private System.Windows.Forms.TextBox textBox1;
    private System.ComponentModel.Container components = null;
    public MyControl()
    {
    InitializeComponent();
    }
    public string Zip
    {
    get
    {
    return textBox1.Text;
    }
    set
    {
    textBox1.Text = value;
    }
    }
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Windows 窗体设计器生成的代码
    private void InitializeComponent()
    {
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    this.textBox1.Location = new System.Drawing.Point(16, 16);
    this.textBox1.Name = "textBox1";
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "100085";
    this.Controls.Add(this.textBox1);
    this.Name = "MyControl";
    this.Size = new System.Drawing.Size(136, 56);
    this.ResumeLayout(false);
    }
    #endregion
    }
    public class Show : System.Windows.Forms.Form
    {
    private System.Windows.Forms.TextBox textBox1;
    private MyControl myControl1;
    private System.ComponentModel.Container components = null;
    ……
    [STAThread]
    static void Main() 
    {
    Application.Run(new Show());
    } private void Show_Load(object sender, System.EventArgs e)
    {
    MyControl Mycontrol1 = new MyControl();
    textBox1.Text = "Zip is:" + Mycontrol1.Zip;
    }
    }
    我设的初始值是“100085”,不设初始值也没有报错呀。
    你检查一下编辑器产生的代码是否正常。
    就是#region到#endregion这一段。
      

  3.   

    Return TxtZip.Text
    中的TxtZip有没有写错?
    要不使用Return CStr(TxtZip.Text)试试?
      

  4.   

    還是不行呢!!我是在default.aspx里面調用的address.ascx里面的txtzip哦!
      

  5.   

    你是不是将自定义控件放在Default.aspx文件中后,在代码文件中没有进行声明啊?自定义的控件不会自动声明的,要手动加上去。在Default.aspx.vb代码中加入如下代码
    Protected WithEvents address1 As address就放在Public Class default
        Inherits System.Web.UI.Page的下面试试看吧。
      

  6.   

    台湾朋友啊,呵呵,欢迎啊
    Berfore you invoke the "address1.Zip",its value is null,so 
    Answer here: address1.Zip=lblMessage.Text
      

  7.   

    ylj1079(菜菜)的是對的!!原來要顯式的聲明用戶自定義空間的!!