[英]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.