我在用户控件中进行自定义回发,简而言之,我使用以下代码进行注册:
public event EventHandler SelectedPersonChanged;
ClientScriptManager cs = Page.ClientScript;
String cbReference = cs.GetCallbackEventReference("'" +
this.UniqueID + "'", "arg", this.UniqueID + "ReceiveServerData", "",
this.UniqueID + "ProcessCallBackError", false);
String callbackScript = "function SelectPeoplePostback(arg, context) {" +
cbReference + "; }";
cs.RegisterClientScriptBlock(this.GetType(), "SelectPeoplePostback",
callbackScript, true);
这很好用,它调用ASP生成的回发函数,我可以在我的代码中处理回发。我当时正在做的是在此控件中触发一个事件,我在此控件的父控件中处理该事件。通过usal eventhandler:
this.SelectPeople.SelectedPersonChanged += SelectPeople_SelectedPersonChanged;
void SelectPeople_SelectedPersonChanged(object sender, EventArgs e)
{
SelectPeople.PeopleID = 0;
// COMBO BOX NEVER REFRESHES ON UI
cboProducts.DataSource = dbProducts.SelectProducts(peopleID, peopleID);
// this should cause a refresh
cboProducts.DataBind();
//MAYBE GENERATE POSTBACK HERE ???? TO REFRESH PAGE
}
问题
我似乎无法在我的事件处理程序中绑定组合框或任何UI项目,现在我怀疑我需要以某种方式刷新页面,即从父页面触发回发将更新组合框,但是我虽然从我的用户控件中触发回发会处理这个问题。