У меня есть пользовательский элемент управления, который 2 каскадных RadCombos. Я пытаюсь добавить их на свою страницу во время выполнения. Проблема в том, что JS-функция Page_Load пользовательского элемента управления никогда не срабатывает. Также всякий раз, когда Page_Load aspx.cs запускает IsPostback, всегда имеет значение true. Кто-нибудь может помочь?
Контрольный код позади:
public partial class ctrlCascadedProcedureDropDown : System.Web.UI.UserControl
{
public int ProcedureTypeSelectedValue { get; set; }
public int ProcedureSelectedValue { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadProcedureTypes();
if (ProcedureTypeSelectedValue > 0)
LoadProcedures(ProcedureTypeSelectedValue.ToString());
rcbProcedureType.SelectedValue = ProcedureTypeSelectedValue.ToString();
rcbProcedure.SelectedValue = ProcedureSelectedValue.ToString();
}
else if (!Page.IsCallback)
{
if (rcbProcedureType != null)
LoadProcedures(rcbProcedureType.SelectedValue);
}
}
protected void rcbProcedureType_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
LoadProcedureTypes();
}
protected void rcbProcedure_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
LoadProcedures(e.Text);
}
protected void LoadProcedureTypes()
{
TARNDB.OpsProcedureType opsProcedureType = new TARNDB.OpsProcedureType();
rcbProcedureType.DataSource = opsProcedureType.GetProcedureTypes().OrderBy(x => x.ProcedureType);;
rcbProcedureType.DataValueField = "ID";
rcbProcedureType.DataTextField = "ProcedureType";
rcbProcedureType.DataBind();
rcbProcedureType.Items.Insert(0, new RadComboBoxItem(""));
}
protected void LoadProcedures(string proceduretypeid)
{
int _proceduretypeid;
if (int.TryParse(proceduretypeid, out _proceduretypeid))
{
TARNDB.OpsProcedure opsProcedure = new TARNDB.OpsProcedure();
rcbProcedure.DataSource = opsProcedure.GetProcedures(_proceduretypeid).OrderBy(x => x.ProcedureName); ;
rcbProcedure.DataValueField = "ID";
rcbProcedure.DataTextField = "ProcedureName";
rcbProcedure.DataBind();
}
}
}
Контрольная наценка:
<div>
<telerik:RadComboBox ID="rcbProcedureType" runat="server"
OnClientSelectedIndexChanging="LoadProcedures"
OnItemsRequested="rcbProcedureType_ItemsRequested" />
<telerik:RadComboBox ID="rcbProcedure" runat="server" Width="250px"
OnClientItemsRequested="ItemsLoaded"
OnItemsRequested="rcbProcedure_ItemsRequested" />
</div>
<script type="text/javascript">
var rcbProcedure;
var rcbProcedureType;
function pageLoad() {
rcbProcedure = $find("<%= rcbProcedure.ClientID %>");
rcbProcedureType = $find("<%= rcbProcedureType.ClientID %>");
alert("in");
}
function LoadProcedures(sender, eventArgs) {
var item = eventArgs.get_item();
rcbProcedure.set_text("Loading...");
// if a procedure type is selected
if (item.get_index() > 0) {
// this will fire the ItemsRequested event of the
// procedures combobox passing the procedureTypeID as a parameter
rcbProcedure.requestItems(item.get_value(), false);
}
else {
// the -Select a continent- item was chosen
rcbProcedure.set_text(" ");
rcbProcedure.clearItems();
}
}
function ItemsLoaded(sender, eventArgs) {
if (sender.get_items().get_count() > 0) {
// pre-select the first item
sender.set_text(sender.get_items().getItem(0).get_text());
sender.get_items().getItem(0).highlight();
}
//sender.showDropDown();
}
</script>
Телефонный код:
public partial class Operations : BasePage
{
public List<DynamicControl> DynamicControls
{
get
{
return (List<DynamicControl>)Session["_DynamicControls"];
}
set
{
Session["_DynamicControls"] = value;
}
}
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
DynamicControls = null;
}
else
{
if (DynamicControls != null && DynamicControls.Count > 0)
{
foreach (DynamicControl control in DynamicControls)
{
ctrlCascadedProcedureDropDown cpd = new ctrlCascadedProcedureDropDown();
cpd.ID = control.ID;
switch (control.PlaceHolder.ID)
{
case "phProcedure":
phProcedure.Controls.Add(cpd);
phProcedure.Controls.Add(new Literal() { Text = "<BR />" });
break;
default:
break;
}
}
}
}
}
protected void btnAddProcedure_Click(object sender, EventArgs e)
{
AddDynamicProcedureControl("Procedure", phProcedure);
}
private void AddDynamicProcedureControl(string name, PlaceHolder placeHolder, int procedureTypeSelectedValue = 0,
int procedureSelectedValue = 0)
{
Control control = LoadControl("~/Controls/ctrlCascadedProcedureDropDown.ascx");
ctrlCascadedProcedureDropDown cpd = (ctrlCascadedProcedureDropDown)control;
int controlCount = (DynamicControls == null ? 0 : DynamicControls.Count);
string ID = string.Concat(name, controlCount.ToString());
cpd.ID = ID;
cpd.ProcedureTypeSelectedValue = procedureTypeSelectedValue;
cpd.ProcedureSelectedValue = procedureSelectedValue;
DynamicControl dc = new DynamicControl() { ID = ID, PlaceHolder = placeHolder };
if (DynamicControls == null)
DynamicControls = new List<DynamicControl>();
DynamicControls.Add(dc);
placeHolder.Controls.Add(cpd);
placeHolder.Controls.Add(new Literal() { Text = "<BR />" });
}
private List<int> GetDynamicList(PlaceHolder placeHolder)
{
List<int> list = null;
list = new List<int>();
foreach (Control control in placeHolder.Controls)
{
if (control is GenericDropDown)
{
int id;
if (int.TryParse(((GenericDropDown)control).SelectedValue, out id) && id > 0)
list.Add(id);
}
}
return list;
}
}
Большое спасибо,
Пол