0
我在.aspx頁面使用公用Sub內runat
命令如下:後來ASP.NET - 如何從VB中檢索Sub的變量?
<% Dim hasLabel %>
<script runat="server">
Public Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Dim fileExt As String
fileExt = System.IO.Path.GetExtension(FileUpload1.FileName)
If (fileExt = ".docx" OR fileExt = ".doc") Then
Try
FileUpload1.SaveAs("path_to_file" & _
FileUpload1.FileName)
Label1.Text = "<div class='centertext'>Statement Successfully Received, Thank You!<br /><br />File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb</div>"
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "Only Word Document files allowed (.doc, .docx)."
End If
Else
Label1.Text = "You have not specified a file."
End If
hasLabel = Label1.Text
End Sub
</script>
下跌的一頁,我想能夠檢查hasLabel
內容,如果它不爲空,而不僅僅是在頁面上輸出,否則,再次輸出表單,如下所示:
<body>
<form id="form1" runat="server">
<% If hasLabel <> "" Than %>
<div class="centertext"><%= hasLabel %></div>
<% Else %>
<div>
<asp:FileUpload ID="FileUpload1" runat="server" class="file" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload File" /> <br />
<asp:Label ID="Label1" runat="server" class="mission_gothic_reg smalltext"></asp:Label>
</div>
<% End If %>
</form>
</body>
我該如何做到這一點?現在,我得到一個錯誤,說:Name 'hasLabel' is not declared
基本上,我想要發生的是...如果文件已被提交,不顯示文件上傳按鈕。當然,我很可能需要改變這一點,只有當它成功上傳並且文件類型正確時才這樣做。但我甚至找不到一個簡單的解決方案,瞭解它是否已正確上傳或不在實際的ASP頁面中。是的,我可以輸出操作標籤的文本,但是如何知道標籤標籤中是否有任何內容以ASP.NET開頭?