views:

35

answers:

2

My current problem, as stated in the title, is that I am trying to create a series of buttons from a custom class within app_code and place them on a master page.

The whole reason for this is I do not want to have to copy and paste event handlers on the content pages.

However, upon the click of these buttons I need for a method on the content page to be called and update html within a div of the content page.

Is there any way to accomplish updating the div of the content page from an event handler in the custom class? Remember, the method that updates the div exists on the content page.

Any help would be greatly appreciated.

A: 

You want to do something like this I think - Declare an event in your custom class. Raise that event on the button click. In your content form handle the raised event:

Custom Class:

Public Event ButonWasClicked(sender as Object, e as EventArgs)

Private Sub HandleClick(sender as Object, e as EventArgs) Handles btn.Click
   RaiseEvent ButonWasClicked(sender,e)
End Sub

Content Form:

   Private Sub HandleCustomClassClick(sender as Object, e as EventArgs) Handles MyCustomClass.ButtonWasClicked
     MyDiv.Controls.Add(New LiteralControl("Custom class button was clicked!!!"))          
   End Sub
brendan
A: 

Don't forget that if you want to access the DIV in code behind you need to give it an Id and runat server:

<div ID="MyDiv" runat="server">

 ...

</div>
Jim