페이지에 드롭 다운 목록의 텍스트 변경시 동적으로로드되는 텍스트 상자가 거의 없습니다. 사용자는이 텍스트 상자에 값을 입력하고 addnewitem 버튼을 클릭합니다. 코드 뒤에는이 텍스트 상자에 입력 된 값을 캡처하고 싶습니다. 그러나 나는 비어있는 것으로 값을 얻는다. Pageload에버튼 클릭 이벤트에서 사용자가 입력 한 값을 가져올 수 없습니다. 동적으로로드 된 텍스트 상자에 값이 입력되었습니다.
내가 studentschool 및 studentcollege의 선택을 바탕으로
protected override void CreateChildControls()
{
base.CreateChildControls();
CreateDynamicControls();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override object SaveViewState()
{
return new Pair(base.SaveViewState(), null);
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(((Pair)savedState).First);
EnsureChildControls();
}
public void CreateDynamicControls()
{
Student= ddlStudentschool.SelectedItem.Text.ToString();
studentcollege= ddlstudentcollege.SelectedValue.ToString();
int rowPos = 0;
DynPanel.BorderStyle = BorderStyle.Solid;
는, 다음과 같은 텍스트 상자 & fieldName에이
Label Mynewlabel = new Label();
Mynewlabel.ID = "lbl" + FldLabel;
Mynewlabel.Text = FldLabel;
Mynewlabel.Visible = true;
Mynewlabel.Font.Bold = true;
DynPanel.Controls.Add(new LiteralControl("<td bgcolor=#333>"));
DynPanel.Controls.Add(Mynewlabel);
DynPanel.Controls.Add(new LiteralControl("</td>"));
if (ControlType == "TextBox")
{
int textBoxLength;
TextBox MynewTextBox = new TextBox();
MynewTextBox.ID = "txt" + Fldname;
MynewTextBox.Width = 100;
MynewTextBox.EnableViewState = true;
MynewTextBox.Enabled = true;
did not paste the whole code
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
CreateDynamicControls();
}
protected void btnAddItem_Click(object sender, EventArgs e)
{
CreateDynamicControls();
if (DynPanel.Controls != null)
{
foreach (Control ctrl in DynPanel.Controls)
{
if (ctrl is TextBox)
{
TextBox _txt = DynPanel.FindControl(ctrl.ID) as TextBox;
int count = DynPanel.Controls.Count;
// txtresult.ID = ctrl.ID;
txtresult.Text = ((TextBox)ctrl).Text;
TextBox txtPath = (TextBox)ctrl.FindControl("");
string result = txtresult.Text;
}
생성됩니다이 method.Then createdynamiccontrols을 참조하는 것이없는 mthd
첫째로 나는 createchildcontrols 메서드가 두 번째로 호출 될 때 객체 참조에 객체 참조가 설정되지 않고 additem c에있는 createdynamiccontrols 메소드가 없다면 핥기 이벤트, 컨트롤은 더 이상 tehre ...
당신이'txtresult.Text'을 설정하고 후속 반복 그것을 삭제하지 않을 확신에 내 이전 대답을 참조? –
@ Edmondson, 이후 ttresult.Text를 지우고 있지 않습니다. – Janaki
@ Edmonson, 내 시나리오는 ondropdownselectedindex가 변경되었습니다. 드롭 다운 선택에 따라 컨트롤을 동적으로로드해야하며 새 항목 추가 버튼을 클릭하면 동적 컨트롤이 있어야합니다. 그러나 dropdowneventselection 및 Additembutton 클릭 이벤트 모두에서이 메서드를 호출 했으므로 포스트 백으로 인해 addnew 항목을 클릭하면 내 값이 새로 고쳐집니다. 그러나 Additembutton 클릭 이벤트에서 loaddynamiccontrols 메서드를 호출하지 않으면 페이지에 컨트롤이 없습니다. 어떻게해야합니까? 도와주세요. – Janaki