繁体   English   中英

如何使用引导控件更改个人资料图片

[英]How to change the profile picture using bootstrap controls

我正在onclick()事件上更改用户个人资料图片。 它越来越

保存在iis服务器中,但不反映aspx页。 当我注销并再次登录时。 它正在更新。 这是我的代码:

Default.aspx的

 <input type="file" id="userPicFileUpload" runat="server" />
        <button runat="server" class="btn btn-info editable-submit" id="btnChangeUserPic" onclick="ChangeUserPic();">Change</button>    

Default.aspx.cs

 protected void btnChangeUserPic2_Click(object sender, EventArgs e)
    {
        try
        {
            string filePath = Server.MapPath("~/Upload/");                            
            HttpPostedFile File = userPicFileUpload.PostedFile;
            string fileExtn = Path.GetExtension(File.FileName).ToLower();
            string filename = System.IO.Path.GetFileName(File.FileName);               
            File.SaveAs(filename);
            lblStatus.Visible = true;
            lblStatus.Text = "Profile picture changed successfully !!";

        }
        catch (Exception ex)
        {               
        }

    }

上传图片后没有刷新。请帮帮我

只需将您的按钮替换为asp按钮,即可使用...

保存图像后,您不会更改图像。

protected void btnChangeUserPic2_Click(object sender, EventArgs e)
{
    try
    {
        string filePath = Server.MapPath("~/Upload/");                            
        HttpPostedFile File = userPicFileUpload.PostedFile;
        string fileExtn = Path.GetExtension(File.FileName).ToLower();
        string filename = System.IO.Path.GetFileName(File.FileName);               
        File.SaveAs(filename);
        lblStatus.Visible = true;
        lblStatus.Text = "Profile picture changed successfully !!";
        profilepic.ImageUrl=filePath+filename;

    }
    catch (Exception ex)
    {               
    }

}

<button>是客户端<button>的客户端标记。

为了能够使用按钮回调,您需要一个绑定到btnClick的<asp:Button>或类似名称。 <asp:Button>是一个服务器端控件,它与背后的代码绑定,但产生一个ClientSide html按钮,单击该按钮将调用服务器。

否则,您需要开始使用ScriptManager。

为避免重复回答众所周知的“问题”,请发送至: http : //www.codeproject.com/Articles/1757/File-Upload-with-ASP-NET

在哪里解释了有关使用ASP.NET WebForms上传文件的所有内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM