我有一个放在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是页面类的受保护字段
答案 0 :(得分:1)
您必须在页面的PreRender
事件中定义ImageUrl
1在事件中查找我们的数据
2将数据保存在页面的变量中
3在PreRender上设置Image的属性
答案 1 :(得分:0)
您的photosListBox不在更新面板中,因此当执行submit_Click()时,所选值不会发送回服务器。