我有一个问题,我似乎一直在绊倒,我有一个下拉框,你可以选择一个数字,创建x个文本框,带有图像按钮,用于调查,图像按钮用于创建“子答案“所以他们可以得到答案的答案所以我的问题是我需要当他们点击图像按钮在原始文本框下创建一个文本框这里是代码。
for (Int32 i = 1; i <= NumberOfAnwsers; i++)
{
Literal l1 = new Literal();
l1.Text = "<tr><td>Answer " + i + " text.</td><td>";
TextBox tb = new TextBox();
tb.ID = "TextBoxAnswer" + i;
tb.EnableViewState = false;
tb.Width = 300;
Literal l3 = new Literal();
l3.Text = "</td><td>";
Literal l2 = new Literal();
l2.Text = "</td></tr>";
RadColorPicker CPI = new RadColorPicker();
CPI.PaletteModes = PaletteModes.WebPalette;
CPI.ID = "RadColorPicker" + i;
CPI.ShowIcon = true;
CPI.SelectedColor = System.Drawing.Color.Black;
ImageButton IBVideo = new ImageButton();
IBVideo.ID = "IBVideo" + i;
IBVideo.ImageUrl = "/images/video-icon.jpg";
IBVideo.ToolTip = "Add Video";
IBVideo.Height = 20;
IBVideo.Width = 20;
ImageButton IBAdd = new ImageButton();
IBAdd.ID = "IBAdd" + i;
IBAdd.ImageUrl = "/images/add-icon.png";
IBAdd.ToolTip = "Add Sub-Answers";
//IBAdd.OnClientClick = "showDialog(" + i + ");return false;";
IBAdd.Height = 20;
IBAdd.Width = 20;
//Add Textbox
PanelAnswersToQuestions.Controls.Add(l1);
PanelAnswersToQuestions.Controls.Add(tb);
PanelAnswersToQuestions.Controls.Add(l3);
PanelAnswersToQuestions.Controls.Add(CPI);
PanelAnswersToQuestions.Controls.Add(IBVideo);
PanelAnswersToQuestions.Controls.Add(IBAdd);
PanelAnswersToQuestions.Controls.Add(l2);
}
正如你所看到的,我只是向面板添加控件,我需要知道ImageBUtton何时被点击我可以添加一个文本框,在这种情况下它可能只是一个文本框。
我希望这很清楚但出于某种原因我不认为这是......抱歉。
答案 0 :(得分:0)
我不确定我的问题是否正确,但如果您需要在页面上动态添加控件,我可以说。
在添加你的控件之前我想你需要找到你需要添加它的控件,添加控件然后分配属性。
PlaceHolder myPlaceHolder = (PlaceHolder)Page.FindControl("PlaceHolder1");
myPlaceHolder.Controls.Add(myButton);
myButton.Text = "Hello World";
如需更详细的说明,请点击http://anyrest.wordpress.com/2010/04/06/dynamically-removing-controls-in-a-parent-page-from-a-child-control/
答案 1 :(得分:0)
我添加了一个radwindow并弹出,通过javascript将数据发送到partent,这为我创建了一个新问题,我无法在javascript中找到动态创建的隐藏字段
function OnClientClose(radWindow) {
var oWnd = $find("<%=RadWindowAddSubAnswer.ClientID%>");
var SubAnswerValues = oWnd.get_contentFrame().contentWindow.document.forms(0).HiddenFieldSubAnswers.value;
alert(SubAnswerValues);
var AnswerID = oWnd.get_contentFrame().contentWindow.document.forms(0).HiddenFieldAnswerID.value;
alert(AnswerID);
var HiddenName = "HiddenFieldSubAnswers" + AnswerID;
alert(HiddenName);
document.getElementById(HiddenName).value = SubAnswerValues;
$get("DivSubAnswers" + AnswerID).innerHTML = SubAnswerValues;
}
“document.getElementById(HiddenName).value = SubAnswerValues;”好像永远都找不到,我也试过$ get(HiddenName).value = SubAnswerValues;似乎无效的两者都返回null作为其后面的代码: HiddenField HFSubAnswers = new HiddenField(); HFSubAnswers.ID =“HiddenFieldSubAnswers”+ i; HFSubAnswers.Value =“0”;