0

Two dropdownlists drop1, drop2 have separate selected index changed. Any dropdown, on selectedindexchanged, goes to another page. If we use back button in browser it goes back to our home page and one of dropdown will be selected position. If we change the other dropdown, it works only the first selected index changed in the coding section

How can we solve this problem?

code

  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);

        }
Adrian Iftode
  • 15,465
  • 4
  • 48
  • 73
ranjenanil
  • 308
  • 2
  • 7
  • 19

2 Answers2

0

If ViewState is off (on the dropdown or any of its parents - all the way up to the page) then the event won't fire. (It should post back though...)

SmartestVEGA
  • 8,415
  • 26
  • 86
  • 139
0

The problem seems to be caused by the caching of your page. I'd say that your two events are triggered, but you can not see it because of redirect

You may disable caching of your form :

        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;

or you may test the eventtarget inside your eventhandlers

    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);

    }
jbl
  • 15,179
  • 3
  • 34
  • 101