ความผิดพลาดคืออาจารย์ 2

บันทึก ASP.NET :: อยากให้ Control บางตัวใช้งานไม่ได้ (enable false)

Posted on: พฤศจิกายน 21, 2008

กำหนดเมื่อ page load ให้ dropdownlist เป็น “โสด” แล้วกำหนด คอนโทรลตัวอื่นที่ไม่เกี่ยวข้องให้ใช้งานไม่ได้

enable control

enable control

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MarryNotShow()

‘control วันที่
If Page.IsPostBack Then
Response.Write(“เกิดวันที่ ” & dateUC1.DVal & “/” & dateUC1.MVal & “/” & dateUC1.YVal)

‘ control radio button เพศ
If radiMale.Checked = True Then
Response.Write(radiMale.Text)
Else
Response.Write(radiFemale.Text)
End If

End If
End Sub


และเมื่อมีเปลี่ยนค่า ใน dropdownlist จาก “โสด” เป็น “สมรส” control ถึงจะสามารถใช้งานได้

enable control

ให้แสดง control เพื่อรับข้อมูลเกี่ยวกับคู่สมรส

Protected Sub ddlMarry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMarry.SelectedIndexChanged
‘check marry
If ddlMarry.SelectedValue = “สมรส” Then
MarryShow()
ElseIf ddlMarry.SelectedValue = “โสด” Then
MarryNotShow()
End If
End Sub

โดยเขียน private sub สองตัว

Private Sub MarryNotShow()
radiYes.Checked = False
radiNo.Checked = False
txtNameMate.Text = “”
txtJobMade.Text = “”
txtJobOfficeMade.Text = “”
txtNameMate.CssClass = “textboxEnable”
txtJobMade.CssClass = “textboxEnable”
txtJobOfficeMade.CssClass = “textboxEnable”

ddlMarryRegis.Enabled = False
radiYes.Enabled = False
radiNo.Enabled = False
txtNameMate.Enabled = False
txtJobMade.Enabled = False
txtJobOfficeMade.Enabled = False
End Sub

 


Private Sub MarryShow()
txtNameMate.CssClass = “”
txtJobMade.CssClass = “”
txtJobOfficeMade.CssClass = “”
ddlMarryRegis.Enabled = True
radiYes.Enabled = True
radiNo.Enabled = True
txtNameMate.Enabled = True
txtJobMade.Enabled = True
txtJobOfficeMade.Enabled = True

End Sub

 

เพิ่งนึกได้ ว่าตอนทำ vb6 สมัยเมินนานมาแล้ว ก็ทำแบบนี้นี่นา

ข้อเสียก็คือ ตอนเลือก สถานภาพสมรส มันจะส่งค่า ispostback ซึ่งจะทำให้หน้าเพจ refresh

(อาจจะทำให้ผู้ใช้รำคาญได้)

ไม่รู้ว่ามีวิธีอื่นที่ดีกว่านี้รึเปล่า..

ป้ายกำกับ: , ,

3 Responses to "บันทึก ASP.NET :: อยากให้ Control บางตัวใช้งานไม่ได้ (enable false)"

รู้สึกว่ามีปัญหาตรง css เพราะหลังจากกำหนดให้ CssClass = “” แล้ว css ที่ใช้กับ page หน้านี้เจ๊งไปเลย

ควรใส่

MaintainScrollPositionOnPostback=”true”

ตรงหัว page ด้วยเพื่อเวลา postback แล้วจะได้ไม่ขึ้นไปอยู่ส่วน top

ใส่ความเห็น

หมวดหมู่

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 335 other subscribers

brush photoshop

Add new tag asp.net atsme banner Blog ไทยโดเมน.in.th brush brush photoshop brush photoshop7 brush photoshop ตึก และ นก brush photoshop นักธุรกิจ Business Marketing Day chiangmai magazine cmhappy cmhappy.com cmtoday cmtoday cmhappy download brush download brushes photoshop CS4 download brush photoshop download บรัช e-atsme flash banner free domani FTP+PHP FW mail meeting menu photoshop brush download PHP RA Red Alert3 reggae sme tab thnic virus web design wordpress Yetii Yuri การทำ flash banner กินเนื้อสด ข้าวยาก หมากแพง ความฝัน ฆ่าควาย ฆ่าหมู่ จ๊อบ บรรจบ ชมรมเว็บมาสเตอร์ & ทำ web ทำเว็บ บรัช โฟโต้ช็อป ประกันชีวิต ปริญญา ปาย สวนบวกหาด สอบกพ สอบภาค ก หนังฆ่าคนดำ หน้าที่ webmaster หมาใจดำ หวยออก 111 หางดง เชียงใหม่ อ.ไชยยันต์ ไชยพร ออกแบบเว็บ เบื่อ เร้กเก้ เลี้ยงดง เว็บ SME เว็บเชียงใหม่ แจก brush photoshop แต่งภาพ แว่นตาเกาหลี แว่นตาแฟชั่น แว่นแฟชั่น
พฤศจิกายน 2008
จ. อ. พ. พฤ. ศ. ส. อา.
 12
3456789
10111213141516
17181920212223
24252627282930

Blog Stats

  • 349,760 hits