页面中的两个下拉列表(冲突)

时间:2012-03-20 08:33:24

标签: c# asp.net dotnetnuke

两个下拉列表drop1,drop2已更改单独的选定索引。 selectedindexchanged上的任何下拉菜单都转到另一页。如果我们在浏览器中使用后退按钮,它将返回到我们的主页,其中一个下拉列表将被选中。如果我们更改另一个下拉列表,它仅适用于编码部分中更改的第一个选定索引

我们如何解决这个问题?

  protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                     string zCenterId="0";

                   if(Request.QueryString["LCID"]!=null)
                    {
                        zCenterId = Request.QueryString["LCID"].ToString();

                    }
                    ManageActivityAdminUIController  ObjCtrl = new ManageActivityAdminUIController();
            List<ManageActivityAdminUIInfo> ObjInfo = ObjCtrl.GetActivityList(zCenterId );
            drplistactivity.DataSource = ObjInfo;
            drplistactivity.DataBind();

            drplistactivity.DataSource = ObjInfo;
            drplistactivity.DataTextField = "ActivityName";
            drplistactivity.DataValueField = "ID";
            drplistactivity.DataBind();
            drplistactivity.Items.Insert(0, new ListItem("<--Select Activity-->", "0"));
                   ManageCoursesController ObjCtrl = new ManageCoursesController();
            List<ManageCoursesInfo> ObjInfo = ObjCtrl.GetCourses(zCenterId );

            drplistcourse.DataSource = ObjInfo;
            drplistcourse.DataTextField = "CourseName";
            drplistcourse.DataValueField = "ID";
            drplistcourse.DataBind();
            drplistcourse.Items.Insert(0, new ListItem("<--Select Course-->", "0"));
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }

        }


  protected void drplistactivity_SelectedIndexChanged(object sender, EventArgs e)
        {
            string url = ResolveClientUrl("~/Activity.aspx?ActivityId="+drplistactivity.SelectedItem.Value);
            Response.Redirect(url);
        }
        protected void drplistcourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            string url = ResolveClientUrl("~/Course.aspx?CourseId=" + drplistcourse.SelectedItem.Value);
            Response.Redirect(url);

        }

2 个答案:

答案 0 :(得分:0)

如果ViewState已关闭(在下拉列表或其任何父级 - 一直到页面),则该事件将不会触发。 (虽然应该回复......)

答案 1 :(得分:0)

问题似乎是由页面缓存引起的。 我会说你的两个事件都被触发了,但由于重定向而无法看到它

您可以停用表单的缓存:

        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
        HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();
        Response.Expires = -1;

或者您可以在事件处理程序中测试eventtarget

    protected void drplistcourse_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(drplistcourse.UniqueID!=Request.Form["__EVENTTARGET"])
             return;
        string url = ResolveClientUrl("~/Course.aspx?CourseId=" + drplistcourse.SelectedItem.Value);
        Response.Redirect(url);

    }