목록 상자 안의 각 항목에 대해 HiddenFields를 동적으로 생성하는 웹 사이트가 있습니다. FindControl() 컨트롤을 찾을 수 없습니다.
foreach (Checklist c in check)
{
lbxCheckListLevel3.Items.Add(c.Name);
HiddenField hf = new HiddenField();
hf.ID = c.Name;
hf.Value = c.Status + ":" + c.ResponseLabels + ":" + c.Prompt + ":" + c.Notes + ":" + c.ResponseValues;
prompt.Controls.Add(hf);
}
에 HiddenField의 값
는 자바 스크립트내에서 변경되는 그리고 저장 버튼을 클릭하면 다음의 온 클릭 기능은 모든 HiddenFields을 통해 이동하고 다시 밖으로 값을 읽어 실행합니다.
for(int i = 0; lbxCheckListLevel3.Items.Count > i; i++)
{
//Update the main checklist with the new information
HiddenField hidden = (HiddenField)FindControl(lbxCheckListLevel3.Items[i].Text);
int index = check.FindIndex(delegate(Checklist c) { return c.Name == lbxCheckListLevel3.Items[i].Text; });
if (check[index].Status != int.Parse(hidden.Value.Split(':')[0]) ||
check[index].Notes != hidden.Value.Split(':')[3] ||
check[index].ResponseValues != hidden.Value.Split(':')[4])
{
check[index].Status = int.Parse(hidden.Value.Split(':')[0]);
check[index].Notes = hidden.Value.Split(':')[3];
check[index].ResponseValues = hidden.Value.Split(':')[4];
check[index].Changed = true;
}
}
내 문제는 FindControl Line이 NULL을 반환한다는 것입니다. IE9에서 개발자 도구를 가져와 올바른 ID로 존재하는지 확인했습니다. 하지만 여전히 NULL을 반환합니다.
정보가 더 필요하면 질문하십시오. 가능한 최선을 다할 것입니다.
편집
다음 줄은 culperate, 나는 때문에 대시 생각합니다. 이 필드의 ID에 표시 되더라도
Environmental Health – Does the application involve any of the following:
자바 스크립트는 여전히 값을 컨트롤을 찾아 변경할 수 있습니다.
대시가있는 다른 것을 발견했으며 그 중 하나는 오류없이 발견되었습니다. 이 줄을 것 같다 만 ...
너와 비슷한 것으로 이것을보십시오. http://stackoverflow.com/questions/7495486/button-click-event-not-firing-within-use-control-in-asp-net/7495550#7495550 –
불행히도 나를 위해 작동하지 않을 정도로 다릅니다. – Seige
좋습니다, 요약하면 viewstate를 컨트롤에 다시 바인딩 할 수 있도록 숨겨진 상자가 있는지 확인해야합니다. 따라서 page_load 이벤트에서 컨트롤을 다시 만듭니다. –