我有一张放在 UpdatePanel 中的图片。我在 button_click 事件中设置了它的 ImageUrl。图像在 App_Data/imagesDirectory 中。为什么网页中没有显示图像?
<asp:Panel ID="Panel1" runat="server" style="direction: ltr">
<asp:ListBox ID="photosListBox" runat="server" Rows="1"></asp:ListBox>
<asp:Button ID="selectButton" runat="server" Text="select"
onclick="selectButton_Click" />
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Image ID="ph" runat="server" />
<br />
<br />
<asp:Button ID="submit" runat="server" onclick="submit_Click"
Text="submit" />
<br />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
我只是在其中设置了与图像控件相关的 ImageUrl 属性。但是,按钮代码:
UpdatePanel2.Visible = true;
submit.Visible = true;
photosListBox.Visible = false;
selectButton.Visible = false;
Users sentUser = (Users)Session["user"];
Gallery sentGallery = (Gallery)Session["gallery"];
string selectedName = photosListBox.SelectedItem.ToString();
int selectedId = Convert.ToInt32(photosListBox.SelectedItem.Value);
ModelContainer ml = new ModelContainer();
Users u = ml.UsersSet.Where(t => t.Username == sentUser.Username).First();
Gallery g = u.Gallery.Where(t => t.Name == sentGallery.Name && t.Id == sentGallery.Id).First();
Photo p = g.Photo.Where(t => t.Name == selectedName && t.Id == selectedId).First();
ph.ImageUrl = MapPath(p.PhotoAdd);
nameTextBox.Text = p.Name;
descriptionTextBox.Text = p.Description;
uploadDateTimeLabel.Text = p.UploadDateTime.ToString();
我还在页面的 PreRender 事件中设置了 ImageUrl 属性。但它不起作用:
protected void Page_PreRender(object sender, EventArgs e)
{
ph.ImageUrl = imageU;
}
imageU 是页面类的受保护字段