◎以上程式範例AspNet03.aspx,如在頁框下不能操作,請開新視窗操作
◎如果有問題歡迎您提出,dnowba很需要有人和我一起討論
Partial Class AspNet03 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Response.Write("二個標示文字的控制項") ' Literal控制項常用來「固定」警告文字的位置。很單純,只有text屬性來取得或設定文字,預設是空白值 Me.Literal1.Text = "這是Literal控制項" ' Label控制項和Literal比較的話,多了style屬性,所以可以使用CSS樣式,變化較多 Me.Label1.Text = "這是Label控制項" Me.Label1.BorderColor = Drawing.Color.AliceBlue ' ===== 設計:輸出文字後在頁面上呈現動態文字 ===== Me.Button1.Text = "送出後顯示動態文字" ' 因為Label控制項預設文字就是"Label",所以為了美化我們可以先讓他先填入空白值 Me.Label2.Text = "" ' ===== 設計:輸出文字後讓Label搭配簡單的JavaScript(警告視窗) ===== Me.Button2.Text = "送出後跳出警告視窗" ' 除了讓Label控制項預設文字變為空白值外,也可以設定隱藏,待按鈕按下時再顯示標示 Me.Label3.Visible = False ' ===== 設計:文字轉換成貨幣、日期格式 ===== Me.Label4.Text = "最後,label控制項的好處我想除了可以寫CSS style、JavaScript外,<br>" _ & "還可以轉換成Framework提供的字串格式,如貨幣、日期…等,以下列舉供參考:<br>" Dim s As String = String.Format("(C) Currency:.........{0:C}" & "<br>" & _ "(D) Decimal:..........{0:D}" & "<br>" & _ "(E) Scientific:.......{1:E}" & "<br>" & _ "(F) Fixed point:......{1:F}" & "<br>" & _ "(G) General:..........{0:G}" & "<br>" & _ "(N) Number:...........{0:N}" & "<br>" & _ "(P) Percent:..........{1:P}" & "<br>" & _ "(R) Round-trip:.......{1:R}" & "<br>" & _ "(X) Hexadecimal:......{0:X}" & "<br>" & _ " default:..........{0}" & "<br>", _ -123, -123.45) Me.Label5.Text = "===貨幣的格式===<hr>" & s Dim d As String = String.Format("(d) Short date:.......{0:d}" & "<br>" & _ "(D) Long date:..........{0:D}" & "<br>" & _ "(t) Short time:..........{0:t}" & "<br>" & _ "(T) Long time:..........{0:T}" & "<br>" & _ "(f) Full date/short time:..........{0:f}" & "<br>" & _ "(F) Full date/long time:..........{0:F}" & "<br>" & _ "(g) General date/short time:..........{0:g}" & "<br>" & _ "(G) General date/long time:..........{0:G}" & "<br>" & _ " default:..........{0}" & "<br>" & _ "(M) Month:..........{0:M}" & "<br>" & _ "(R) RFC1123:..........{0:R}" & "<br>" & _ "(s) sortable:..........{0:s}" & "<br>" & _ "(u) Universal sortable:..........{0:u}" & "<br>" & _ "(U) Universal full date/time:..........{0:U}" & "<br>" & _ "(Y) Year:..........{0:Y}" & "<br>", _ DateTime.Now()) Me.Label6.Text = "===時間的格式===<hr>" & d End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Label2.Text = "謝謝您輸入資料" End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click ' 這個按鈕事件裡說明了Label可以放一些JavaScript,而且底下這個蠻有趣的(我還不知道怎麼應用就是了…) ' 我們可以用事件中發生的順序來製造pop-up視窗,待確認後程式才會繼續執行(在這裡就是Label3.Visible = True) Me.Label3.Text = "<script>window.alert('感謝你輸入資料');</script> 資料已送出!!!" Me.Label3.Visible = True End Sub End Class
沒有留言:
張貼留言