我有一個圖像控件和按鈕control.I要選擇新的圖像和按鈕點擊更新圖像。 cs文件如下:Asp.Net更新圖片網址
protected void Button2_Click(object sender, EventArgs e)
{
//choose new image
}
我有一個圖像控件和按鈕control.I要選擇新的圖像和按鈕點擊更新圖像。 cs文件如下:Asp.Net更新圖片網址
protected void Button2_Click(object sender, EventArgs e)
{
//choose new image
}
你可以嘗試這樣的事情在你的.ASPX:
<form id="form1" runat="server">
<asp:Image ID="Image1" runat="server" /><br /><br />
<asp:FileUpload id="FileUploadControl" runat="server" />
<asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />
<br /><br />
<asp:Label runat="server" id="StatusLabel" text="Upload status: " />
</form>
而在你.CS:
protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/YourImageFolder") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
Image1.ImageUrl = "~/YourImageFolder" + filename;
}
catch(Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
我想這樣做動態 – Zamir10