2

I have a .NET 4.0 Web Application project written in VB. I have a Master Page from which all subsequent webpages are derived. Each webpage comprises of one or more Web User Controls. One particular WUC comprises of a Panel that the user can click on - it acts and feels like a button - taking them to another page of relevant data.

I now need to capture the OnClick event of the panel and carry out a task before redirecting the user to another page. The solution I have tried so far includes:

(1) Insert the following code after the Partial Class... opening statements on the WUC:

Public Event Click(ByVal sender As Object, ByVal e As EventArgs)

Protected Overridable Sub OnClick(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Click
    RaiseEvent Click(Me, e)
End Sub

(2) Include the following subroutine within the WUC:

Public Sub common_button1_Click1(sender As Object, e As EventArgs) Handles Me.Click
  ' Do Stuff here
End Sub

(3) Have the following statement within the Page_Prerender subroutine of the WUC:

AddHandler Me.Click, AddressOf common_button1_Click1

How do I now use this event handler, so that when I click on the WUC it fires? I was thinking that the reference to the WUC on my webpage would have the attribute 'OnClick' within it and point to 'common_button1_Click', but the option does not appear to be within the IntelliSense of Visual Studio. Example ...

Many thanks in anticipation of your responses.

4

1 に答える 1

0

私たちの実装では、AddHandler コードを PreRender の代わりに Page_Load に入れました。これは、ポストバックであるかどうかに関係なく、すべての単一のロードにも追加されます。

于 2013-06-28T22:43:33.920 に答える