display an image [closed]
how to browse an image location u开发者_开发百科sing fileupload and display it into an image control
Try this:
In your asp.net page:
<form id="form1" runat="server">
<div>
<asp:Image ID="uploadedImage" runat="server" />
<asp:FileUpload ID="fileUploadControl" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="submit" />
</div>
</form>
And in its code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (fileUploadControl.HasFile)
{
string location = "Images/imageName.png";
fileUploadControl.SaveAs(Server.MapPath("~/" + location));
uploadedImage.ImageUrl = location;
}
}
}
The code is not perfect. But it gives you a hint...
精彩评论