我的主页上有一个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
但是gimme an Error,的线路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
而不是
testlinkbutton.Click += New EventHandler(AddressOf LinkButton1_Click)
你可以试试
AddHandler testlinkbutton.Click, AddressOf LinkButton1_Click
请参阅如何:使用代码添加事件处理程序