I have the MPE, mpeNew inside an Updatepanel, with a button btnClose inside. It should show up with the selectedIndexChange event of few dropdownlists on page.

C#:

protected void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
  if(ddlCustomer.SelectedIndex==1)
   {
     ViewState["sender"] = sender; //MPE shows up only when this line's commented
     mpeNew.show();
   }
}

protected void btnClose_Click(object sender, EventArgs e)
{
   mpeNew.Hide();
   DropDownList ddl = (DropDownList)ViewState["sender"];
   ddl.SelectedIndex = 0;
}

The Modal shows up only when the viewstate declaration is commented. But It is acctually needed to know which dropdown opened the Modal. Also tried using this dropdown as a trigger in updatepanel. There is no error. The modal just wont pop. Where am I going wrong. Or is there any other way to get what I want.

有帮助吗?

解决方案

Dropdown control is not serializable so when tring to store it in the viewstate the code breaks. Instead of saving the sender it would be more appropriate to save the ID of the dropdown in the ViewState. By the ID you can always find the control usin FindControl("Id") function. Exaple based on your code:

ViewState["sender"] = ddlControl.ID;

DropDownList ddl = (DropDownList)FindControl(ViewState["sender"]);

Hope this helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top