我有一个包含usercontrol(ascx)的页面(aspx)。在aspx的回发中,我想阅读ascx中的一些控制值。因此,在阅读good articles后,我在我的aspx中创建了一个事件,在回发时触发。事件处理程序位于ascx中,只是将我感兴趣的值写入视图状态,以便父页面可以读取它们。 问题是我的事件处理程序永远不会被击中,即使我看到事件在我逐步执行代码时引发。所以,我的代码炸弹试图读取视图状态(这是空的)用户控件中的自定义事件
这里的时候,就是我在我的aspx得:
Partial Public Class Visitor
Inherits System.Web.UI.Page
Public Event PagePostback(ByVal sender As Object, ByVal e As System.EventArgs)
.
.
.
Private Sub SaveAssignment(ByVal e As EventArgs)
RaiseEvent PagePostback(Me, e) 'Tell usercontrol to post its control values to the viewstate
'read viewstate and save its values
End Sub
下面是在我的ascx:
Partial Public Class GenVstr
Inherits System.Web.UI.UserControl
Protected WithEvents pageVisitor As Visitor
Public Property visitType() As String
Get
Return ViewState("visitType").ToString
End Get
Set(ByVal value As String)
ViewState("visitType") = value
End Set
End Property
Public Sub ParentPostback(ByVal sender As Object, ByVal e As EventArgs) Handles pageVisitor.PagePostback
With Me
If optVIP.Checked Then .visitType = "VIP"
If optFamily.Checked Then .visitType = "Family"
If optMedia.Checked Then .visitType = "Media"
If optGuest.Checked Then .visitType = "Guest"
If optConference.Checked Then .visitType = "Conference"
End With
End Sub
哦,我碰巧提到我正在动态加载ascx? :)