2

我的母版页上有一个LinkButton,并想在我的内容页面中处理它,

所以我在页面加载时写了这样的代码:

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

        If Session("UserID") Is Nothing Then
            Session("UserID") = Request.ServerVariables("LOGON_USER").Replace("INA\", "")
        End If

        Me.lbleMessage.Text = ""
        Dim lblUaname As Label = DirectCast(Master.FindControl("lblUname"), Label)
        lblUaname.Text = Session("UserID").ToString

        Dim testlinkbutton As LinkButton = DirectCast(Master.FindControl("LinkButton1"), LinkButton)
        testlinkbutton.Click += New EventHandler(AddressOf LinkButton1_Click)

        If Not IsPostBack Then
            Me.lbleMessage.Text = ""
            If Session("UserID") <> "svaldano" Then
                'If CAuth.AuthUser(Session("UserID"), "20") Then

                'Else
                '     Response.Redirect("login.aspx")
                'End If
                FillDataWO()
                FillDataTC()
            ElseIf Not (Session("Username") Is Nothing) Then
                'If CAuth.AuthUser(Session("Username"), "20") Then

                'Else
                '     Response.Redirect("login.aspx")
                'End If
                If Session("Username") = "sv" Then
                    FillDataWO()
                    FillDataTC()
                Else
                    Response.Redirect("login.aspx")
                End If

            ElseIf Session("Username") Is Nothing Then
                Session("UserID") = Request.ServerVariables("LOGON_USER").Replace("BMJAKARTA\", "")
                Response.Redirect("login.aspx")
            End If

        End If
    End Sub

但是testlinkbutton.Click += New EventHandler(AddressOf LinkButton1_Click)给我一个错误的行,

Public Event Click(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

那么我不能使用我的代码是真的吗?因为我只知道raiseevent

4

1 回答 1

2

代替

    testlinkbutton.Click += New EventHandler(AddressOf LinkButton1_Click)

你可以试试

    AddHandler testlinkbutton.Click, AddressOf LinkButton1_Click

请参阅如何:使用代码添加事件处理程序

于 2013-08-20T11:02:27.157 回答