C# Asp:Image';s图像不';更改图像Url后,请不要更改

C# Asp:Image';s图像不';更改图像Url后,请不要更改,c#,image,imageurl,C#,Image,Imageurl,我正在visual studio中使用C语言创建一个Web应用程序,我是asp的新手。我正在尝试将一个文件上载到我的Web应用程序,然后在页面上载之后(在按下上载按钮之后)在asp:Image上显示上载的文件。更改asp:Image的ImageUrl(ImageUrl)后,上载的图像将不会显示在asp:Image中,但当我自己刷新页面时(按F5),将显示图像。我试图在上传按钮的点击事件结束时再次重定向页面,但没有成功。我怎样才能解决这个问题?谢谢 Html: 你可以发布你的onLoad方法吗?

我正在visual studio中使用C语言创建一个Web应用程序,我是asp的新手。我正在尝试将一个文件上载到我的Web应用程序,然后在页面上载之后(在按下上载按钮之后)在
asp:Image
上显示上载的文件。更改
asp:Image
ImageUrl
ImageUrl
)后,上载的图像将不会显示在
asp:Image
中,但当我自己刷新页面时(按
F5
),将显示图像。我试图在上传按钮的点击事件结束时再次重定向页面,但没有成功。我怎样才能解决这个问题?谢谢

Html:



你可以发布你的onLoad方法吗?你可以设置这个值,然后重定向。浏览器将发出新请求,值集将被丢弃。但当我刷新时,它将工作。我正在更改asp:Image引用的映像。正如我在上面写的,当我不放置重定向行时,它也不会工作。
<asp:Image runat="server" ID="imageProfile" /> 

<asp:FileUpload runat="server" ID="fileUploadProfile" />

<asp:ImageButton ImageUrl="~/Images/Uplaod.png" ID="imageButtonUpload"
runat="server" OnClick="imageButtonUpload_Click" />
protected void imageButtonUpload_Click(object sender, ImageClickEventArgs e)
{
    int ID = Convert.ToInt16(labelID.Text);

    if (fileUploadProfile.HasFile)
    {
        SqlConnection cnn = new SqlConnection("Data Source=.;Initial Catalog=Session5_HomeWork;User ID=sa;Password=*************");

        cnn.Open();

        string Command = "Select GuidName from Table_AccountImages where ID = @ID";
        SqlCommand cmd = new SqlCommand(Command, cnn);

        cmd.Parameters.AddWithValue("ID", ID);
        string GuidName = cmd.ExecuteScalar().ToString();

        cnn.Close();

        fileUploadProfile.SaveAs(MapPath("~/Profile Images/" + GuidName));
        imageProfile.ImageUrl = "~/Profile Images/" + GuidName;

        Response.Redirect(Request.RawUrl);
    }
}
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadImage();
    }
}


private void LoadImage()
{
    int ID = Convert.ToInt16(labelID.Text);
     SqlConnection cnn = new SqlConnection("Data Source=.;Initial Catalog=Session5_HomeWork;User ID=sa;Password=soroush");

    cnn.Open();

    string command = "Select GuidName from Table_AccountImages Where ID = @ID";
    SqlCommand cmd = new SqlCommand(command, cnn);

    cmd.Parameters.AddWithValue("ID", ID);

    try
    {
        imageProfile.ImageUrl = "~/Profile Images/" + cmd.ExecuteScalar().ToString();
    }
    catch (Exception)
    {
        imageProfile.ImageUrl = "~/Profile Images/Default.png";
    }

    cnn.Close();
}