动态创建控件后,它不允许单击 [英] After creating control dynamicly it does not allow click
问题描述
列表与LT;串GT; controlIdList = new List< string>(); //在每个回发上存储控件ID
int counter = 0; // count组合框数
protected override void LoadViewState (对象保存状态)
{
base.LoadViewState(savedstate);
controlIdList =(List< string>)ViewState [controlIdList] ;
foreach(controlIdList中的字符串id)
{
counter ++;
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID = id;
Cb.DataSource = sdSku;
Cb.TextField = SkU;
Cb.ValueField =SkU;
Cb.ValueType = typeof(string);
Cb.Columns.Add( SKU);
Cb.Columns.Add(Model);
Cb.Columns.Add(Name);
Cb.Attributes.Add(runat,server);
Cb .DataBind();
LiteralControl lineBreak = new LiteralControl(
);
PlaceholderSku.Controls.Add(Cb);
PlaceholderSku.Controls.Add(lineBreak);
}
}
protected void Page_Load(object sender,EventArgs e)
{
}
protected void btnAddSku_Click(object sender,EventArgs e)
{
counter ++;
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID =SkuComboBox+计数器;
LiteralControl lineBreak = new LiteralControl(
);
PlaceholderSku.Controls.Add(Cb);
PlaceholderSku.Controls.Add(lineBreak);
controlIdList.Add( Cb.ID);
ViewState [controlIdList] = controlIdList; //存储ids
}
List<string> controlIdList = new List<string>();//to store control Id on each postback
int counter = 0;//count Number of Comboboxes
protected override void LoadViewState(Object savedstate)
{
base.LoadViewState(savedstate);
controlIdList = (List<string>)ViewState["controlIdList"];
foreach( string id in controlIdList)
{
counter++;
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID = id;
Cb.DataSource = sdSku;
Cb.TextField = "SkU";
Cb.ValueField = "SkU";
Cb.ValueType = typeof(string);
Cb.Columns.Add("SKU");
Cb.Columns.Add("Model");
Cb.Columns.Add("Name");
Cb.Attributes.Add("runat", "server");
Cb.DataBind();
LiteralControl lineBreak = new LiteralControl("
");
PlaceholderSku.Controls.Add(Cb);
PlaceholderSku.Controls.Add(lineBreak);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddSku_Click(object sender, EventArgs e)
{
counter++;
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID = "SkuComboBox" + counter;
LiteralControl lineBreak = new LiteralControl("
");
PlaceholderSku.Controls.Add(Cb);
PlaceholderSku.Controls.Add(lineBreak);
controlIdList.Add(Cb.ID);
ViewState["controlIdList"] = controlIdList;//storing ids
}
推荐答案
创建对象时不添加点击处理程序:
You don't add a click handler when you create the object:
Cb.Attributes.Add("runat", "server");
Cb.DataBind();
Cb.Click += new EventHandler(btnAddSku_Click);
可能有帮助。
这篇关于动态创建控件后,它不允许单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!