1
顯然我是一個總noob,這對你們中的一些人很簡單,但我不明白爲什麼其餘的子作品,但button1.Text =「上傳,請稍候...」似乎被完全忽略。爲什麼點擊按鈕時asp.net onclick事件不會改變按鈕文本?
該按鈕應該改變文本時點擊,但沒有方法我已經嘗試過與我的網頁。
任何想法?這裏是我簡單的上傳表單頁面:
<%@ Page aspcompat=true %>
<% ' import all relevant namespaces %>
<%@ import namespace="System" %>
<%@ import namespace="System.Drawing" %>
<%@ import namespace="System.Drawing.Imaging" %>
<%@ import namespace="System.IO" %>
<html>
<head>
<title>Photo 1 Upload</title>
</head>
<body bgcolor="#000000">
<p>
<table align="center" bgcolor="white" cellpadding="5" cellspacing="2" border="2" width="">
<tr>
<td align="center" valign="middle" nowrap bgcolor="554aa1">
<font face="arial" color="white" size="5">
<b>Click the "Browse..." button to select your
<br>photo then click "Upload"</b>
<p>
</font>
<font face="arial" color="white" size="4">
Note: Image must be .jpg format and less than 4MB
</font>
</td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#cccccc">
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload Photo" /> <br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
<p>
</td>
</tr>
</table>
</body>
</html>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object,ByVal e As System.EventArgs)
button1.Text="Uploading, Please Wait..."
If FileUpload1.HasFile Then
Try
Dim Ext
Ext = Lcase(Right(FileUpload1.PostedFile.FileName, 3))
If Ext = "jpg" or Ext = "peg" Then
FileUpload1.SaveAs(Server.MapPath("..\" & Session("user_name") & "\photos\photo1_raw.jpg"))
response.redirect("done.asp?action=done&photo=1#photos")
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUpload1.PostedFile.ContentType
Else
Label1.Text = "ERROR: Nothing Saved - Photo must be a .jpg or .jpeg format."
end if
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
</script>
我實際上已經嘗試將javascript添加到此按鈕,但在此按鈕類型上它也被忽略。 – AmazingChase 2010-09-10 16:08:07
解決方案非常難以實現,但一旦我找到答案,就很簡單。您只需在按鈕上添加OnClientClick =「this.value ='正在上傳,請稍候...'」。然後,您可以在提交表單之前更改按鈕的文本。希望這可以幫助別人,因爲我浪費了至少2個小時的時間。 :) – AmazingChase 2010-09-10 17:02:42
@AmazingChase:您可以提交您的解決方案作爲問題的答案,以幫助其他人遇到同樣的問題。 – Isaac 2012-09-11 06:05:25