HOME > .NET Framework > Forum > รบกวนช่วยหน่อยครับ คือผมมี Dropdown อยู่ตัวหนึ่งใน ไฟล์ a.aspx กับ ตัว requiredfieldvalidator อยู่ในไฟล์ user control b.ascx
รบกวนช่วยหน่อยครับ คือผมมี Dropdown อยู่ตัวหนึ่งใน ไฟล์ a.aspx กับ ตัว requiredfieldvalidator อยู่ในไฟล์ user control b.ascx
Protected Sub ChangedStatus(sender As Object, e As EventArgs)
If DirectCast(sender, DropDownList).SelectedItem.ToString = "ยื่นคำขอ" Then 'If selected ยื่นคำขอ --> Set ReqCalendarPopup1 not working
'Create object from usercontrol
Dim objTestControl As Controls_ctlCalendarSimple = DirectCast(Page.FindControl("Controls_ctlCalendarSimple"), Controls_ctlCalendarSimple)
'Create ReqCalendarPopup1 from object
Dim ReqCalendarPopup1 As RequiredFieldValidator = objTestControl.FindControl("ReqCalendarPopup1")
'Set ReqCalendarPopup1 to not working
ReqCalendarPopup1.Enabled = True
Else ' --> Set ReqCalendarPopup1 working
'Create object from usercontrol
Dim objTestControl As Controls_ctlCalendarSimple = DirectCast(Page.FindControl("Controls_ctlCalendarSimple"), Controls_ctlCalendarSimple)
'Create ReqCalendarPopup1 from object
Dim ReqCalendarPopup1 As RequiredFieldValidator = objTestControl.FindControl("ReqCalendarPopup1")
'Set ReqCalendarPopup1 to not working
ReqCalendarPopup1.Enabled = False
End If
End Sub
Tag : .NET, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x)
Date :
2015-08-05 15:20:28
By :
Mr.T-Bag
View :
1321
Reply :
18
No. 1
Guest
b.ascx.Designer.vb
Code (VB.NET)
'Change Protected WithEvent to Public WithEvent (มีคำเตือนเล็กน้อยไม่ต้องสนใจ)
Public WithEvents ReqCalendarPopup1 As Global.System.Web.UI.WebControls.RequiredFieldValidator
a.aspx
Code (VB.NET)
Dim uctrl As Controls_ctlCalendarSimple = Me.FindControl("Controls_ctlCalendarSimple")
If uctrl isnot Nothing Then
uctrl.ReqCalendarPopup1.Sexybled = True
End If
ตรงนี้คือ Code หน้า user control ครับ ผมหาไฟล์ b.ascx.designer.vb ไม่เจอ ผมเลยสร้าง ฟังก์ชันด้านล่างให้ตัว ReqiuredFiealdValidator มันเป็น Public Code (b.ascx)
' Set property to ReqCalendarPopup1
Public WriteOnly Property ReqCtr() As Boolean
Set(ByVal value As Boolean)
ReqCalendarPopup1.Enabled = value
End Set
End Property
If DirectCast(sender, DropDownList).SelectedItem.ToString = "ยื่นคำขอ" Then
Dim uctrl As Controls_ctlCalendarSimple = Me.FindControl("Controls_ctlCalendarSimple")
uctrl.ReqCtr = False
Else
Dim uctrl As Controls_ctlCalendarSimple = Me.FindControl("Controls_ctlCalendarSimple")
uctrl.ReqCtr = True
End If
Protected Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Dim mc = Me.Master.FindControl("MainContent")
If mc IsNot Nothing Then
Dim uctrl = mc.FindControl("WebUserControl99")
If uctrl IsNot Nothing Then
Dim b As Button = uctrl.FindControl("btnSubmit")
If b IsNot Nothing Then
b.Enabled = False
b.Text = "Hello World"
End If
Dim rfv As RequiredFieldValidator = uctrl.FindControl("rfv99")
If rfv IsNot Nothing Then
rfv.Enabled = True
End If
Dim txtTest As TextBox = uctrl.FindControl("txtTest")
If txtTest IsNot Nothing Then
txtTest.Text = "Hello girl"
End If
End If
End If
End Sub
Protected Sub ChangedStatus(sender As Object, e As EventArgs)
If DirectCast(sender, DropDownList).SelectedItem.ToString = "ยื่นคำขอ" Then
Dim mc = Me.Master.FindControl("ContentPlaceHolder1")
If mc IsNot Nothing Then
Dim uctrl = mc.FindControl("dtpCOD")
If uctrl IsNot Nothing Then
Dim rfv As RequiredFieldValidator = uctrl.FindControl("ReqCalendarPopup1")
If rfv IsNot Nothing Then
rfv.Enabled = False
End If
End If
End If
Else
Dim mc = Me.Master.FindControl("ContentPlaceHolder1")
If mc IsNot Nothing Then
Dim uctrl = mc.FindControl("dtpCOD")
If uctrl IsNot Nothing Then
Dim rfv As RequiredFieldValidator = uctrl.FindControl("ReqCalendarPopup1")
If rfv IsNot Nothing Then
rfv.Enabled = True
End If
End If
End If
End If
End Sub