我的母版页上有一个 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)' 是一个事件,不能直接调用。使用“RaiseEvent”语句引发事件。
那么我真的无法使用我的代码吗?因为我只知道 raiseevent
最佳答案
而不是
testlinkbutton.Click += New EventHandler(AddressOf LinkButton1_Click)
你可以尝试一下
AddHandler testlinkbutton.Click, AddressOf LinkButton1_Click
关于asp.net - 处理内容页面上的点击事件母版控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18332271/