a.ascx里面有一个dropdownlist里面有1~6个值,定义一个属性
private _Link As String
Public Property Link() As String
        Get
            Return _Link
        End Get
        Set(ByVal value As String)
            _Link = value
        End Set
End Property在dropdownlist的SelectedIndexChanged事件里面
Dim ChangePage As String
ChangePage = String.Format("{0}?Page={1}", Link, PageChange.SelectedValue.ToString)
Response.Redirect(ChangePage)在引用a.ascx的页面b.aspx里面的Page_Load事件里面
If Not Page.IsPostBack Then
a1.Link=变量(确定有值)    'a1为a.ascx的实列名
End If为什么触发SelectedIndexChanged事件后Link的值始终为空呢?

解决方案 »

  1.   

    检查AutoPastBack 是否设为true ;还有定义link时试试加上页状态 ViewState
      

  2.   

    建议使用委托来处理
    自定义一个参数类,例如:
    public class LogInOutEventArgs : EventArgs
    {
        private LogInClickType type;
        private bool result;
        private string userName;    public LogInOutEventArgs(LogInClickType type,bool result):base()
        {
            this.type = type;
            this.result = result;
        }
        public LogInClickType Type
        {
            get { return this.type; }
        }
        public bool Result
        {
            get { return this.result; }
        }    public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
    }控件里面
    public delegate void LogInOutClickHandler(object sender, LogInOutEventArgs e);public partial class LogInOutControl : System.Web.UI.UserControl
    {
        public event LogInOutClickHandler LogInOutClick; protected void ButtonLogIn_Click(object sender, EventArgs e)
        {
            OnLogInOutClick(this, new LogInOutEventArgs(LogInClickType.LongIn, CustomValidate(this.TextBoxUserName.Text, this.TextBoxPassword.Text)));
        }
     private void OnLogInOutClick(object sender, LogInOutEventArgs e)
        {
            e.UserName = this.TextBoxUserName.Text;
            if (LogInOutClick != null)
                LogInOutClick(this, e);
        }
    }使用控件的代码:
    protected void Page_Load(object sender, EventArgs e)
        {
            this.LogInOutControl1.LogInOutClick += new LogInOutClickHandler(LogInOutControl1_LogInOutClick);
        }
     private void LogInOutControl1_LogInOutClick(object sender, LogInOutEventArgs e)
        {
            switch (e.Type)
            {
                case LogInClickType.LongIn:
                    this.LabelMsg.Text = e.UserName + "你点击了登录按钮,操作结果:" + e.Result.ToString();
                    break;
                case LogInClickType.LongOut:
                    this.LabelMsg.Text = "你点击了注销按钮,操作结果:" + e.Result.ToString();
                    break;
            }
        }
    }
      

  3.   

    Public Property Link() As String
            Get
                Return _Link
            End Get
            Set(ByVal value As String)
                _Link = value
            End Set
    End Property
    属性值没有存在viewstate或其他能保存状态的对象里, postback后当然取不到. SelectedIndexChanged在postback后触发