我在Page_Init上添加了一组图像,点击某些按钮我想更新这些图像。由于某种原因,它不起作用。为什么呢?
这是我的代码:
protected void Page_Init(object sender, EventArgs e)
{
...
for (int i = 0; i < questionsCount; i++)
{
TableRow newTableRow = new TableRow();
TableTestAnswers.Rows.Add(newTableRow);
TableCell questionNumberCell = new TableCell();
newTableRow.Cells.Add(questionNumberCell);
LinkButton questionNumberLinkButton = new LinkButton();
questionNumberCell.Controls.Add(questionNumberLinkButton);
questionNumberLinkButton.Text = ((char)(i + 'A')).ToString();
TableCell answersCell = new TableCell();
newTableRow.Cells.Add(answersCell);
answersCell.ID = "AnswersCell-" + i.ToString();
for (int j = 0; j < answersCount[i]; j++)
{
Image answerImage = new Image();
answersCell.Controls.Add(answerImage);
answerImage.ID = "Answer-" + i.ToString() + "-" + j.ToString();
answerImage.ImageUrl = Resources.Images.AnswerEmptySquareUrl;
}
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
...
Image answerImage = (Image)TableTestAnswers.FindControl(
"Answer-" + questionIndex.ToString() + "-" + answerIndex.ToString());
answerImage.ImageUrl = Resources.Images.AnswerMarkedUrl;
answerImage.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
}
我可以看到ButtonSubmit找到正确的控件并更改其属性,但在对客户端的响应中,我仍然看到旧图像。救命啊!
答案 0 :(得分:0)
这可能是图像缓存的情况,即新图像的文件名是否与旧图像的文件名相同?