各位.NET高手们,我这里有一个问题,写了一个自定义控件,但是,不自动提交,谁能帮我修改一下啊,我是初学者,实在不知道问题的所在了,由于代码太长,就不往上贴了,如果有能够帮我的,加我QQ吧, 我给发过去,在这里非常感谢了,实在是愁了我一天啊。我QQ271690197

解决方案 »

  1.   

    http://www.jzxue.com/wangzhankaifa/asp-net/201208/07-13475.html控件类必须实现IPostBackDataHandler接口,并实现LoadPostData和RaisePostDataChangedEvent方法。
      

  2.   

    可不可以呢,我是则接触.NET不久的,拜托…
      

  3.   

    大神哪谁来救救我哪,无奈原码附上,不自动提交,哪里有问题啊,自定义控件的代码using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;public partial class CustomerDropDown : System.Web.UI.UserControl, IPostBackDataHandler
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //this.TextBox1.TextChanged+=new EventHandler(TextBox1_TextChanged);
        }        /// <summary>
        /// 原始列表框的数据源
        /// </summary>
        public Object DataSource
        {
            get
            {
                return this.ListBox1.DataSource;
            }
            set
            {
                this.ListBox1.DataSource = value;
            }
        }
        /// <summary>
        /// 原始数据的绑定成员
        /// </summary>
        public String DataMember
        {
            get
            {
                return this.ListBox1.DataMember;
            }
            set
            {
                this.ListBox1.DataMember = value;
            }
        }
        /// <summary>
        /// 原始数据的绑定字段
        /// </summary>
        public String DataTextField
        {
            get
            {
                return this.ListBox1.DataTextField;
            }
            set
            {
                this.ListBox1.DataTextField = value;
            }
        }    /// <summary>
        /// 列表
        /// </summary>
        public ListItemCollection Items
        {
            get
            {
                return this.ListBox1.Items;
            }    }
        /// <summary>
        /// 选中项的索引
        /// </summary>
        public int SelectedIndex
        {
            get
            {
                return this.ListBox1.SelectedIndex;
            }
            set
            {
                this.ListBox1.SelectedIndex = value;
            }    }
        /// <summary>
        /// 选中值
        /// </summary>
        public object SelectedValue
        {
            get
            {
                return this.ListBox1.SelectedValue;
            }
        }
        /// <summary>
        /// 输入框的值
        /// </summary>
        public String Text
        {
            get
            {
                return this.TextBox1.Text;
            }
            set
            {
                this.TextBox1.Text = value;
            }
        }
      
           
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            //这个地方写自己的引用事件从程序
            if (OnTextChangeCustomer != null)
            {
                
                OnTextChangeCustomer(sender, e);
            }
        }   //public delegate  void  OnChangeCustomer(Object s,EventArgs e );
       public event EventHandler OnTextChangeCustomer;   public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
       {
          // throw new NotImplementedException();
           string postedValue = postCollection[postDataKey];
           string PresentValue = Text;
           
           if (PresentValue == null || postedValue != PresentValue)
           {
               Text = postedValue;
               return true;
           }
           return false;
       }
       //public bool AutoPostBack
       //{
       //    get
       //    {
               
       //    }
       //}
       public void RaisePostDataChangedEvent()
       {
          // throw new NotImplementedException();
           OnTextChangeCustomer(null , EventArgs.Empty);
       }
    }