I am having a very difficult time understanding how to access (and code) click events from a server control that is loaded onto the base page inside a user control.
My page layout is basically:
User control containing navigation links (using LinkButtons)
Page content displayed depending on which LinkButton is clicked
End Base page
Here is my aspx_ex.aspx file:
Here is my code-behind file (aspx_ex.aspx.vb) for the .aspx file:
<%@ Page Language="VB" Debug="True"%>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Register TagPrefix="MyMenu" TagName="A_Menu" Src="aspx_menu.ascx" %>
<%@ Reference Control="firstlink.ascx" %>
<%@ Reference Control="something.ascx" %>
<%@ Reference Control="other_one.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<p><asp:PlaceHolder id="mycontent" runat="server" /></p>
Here is the user control file aspx_menu.ascx:
Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs)
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
And the code-behind (aspx_menu.ascx.vb) for the user control:
<asp:LinkButton id="firstlink" Text="Home" OnClick="myClick" runat="server" />
<asp:LinkButton id="something" Text="Something" OnClick="myClick" runat="server" />
<asp:LinkButton id="other_one" Text="Other Thing" OnClick="myClick" runat="server" />
I know this is pretty messed up. If I have all the LinkButton and the "myClick" event all on the .aspx page, it works just fine. As soon as I separate things out, I get this error message:
Public Class menuClick
Public Event myClick as EventHandler
Private Sub myClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim myStringBuilder as StringBuilder
Dim myCtl as UserControl
Dim junk as string
junk = sender.ClientID.ToString()
myStringBuilder = New StringBuilder(junk)
junk = myStringBuilder.ToString()
myCtl = LoadControl(junk)
BC30456: 'myClick' is not a member of 'ASP_.aspx_menu_ascx'.
I have searched and searched many forums looking for an answer. I know the answer is out there, but all posts that I've found are too generic, like "you need to link a public event handler to the controls private class and you should be fine". They don't contain specific code with info on where to place that code.
Ultimately, what I want to do is have the output from the LinkButton load the user control into a placeholder on the hosting page. When new content is called for by clicking another LinkButton, the new content should replace the old. There should be default content in the placeholder when first accessing the page.
I feel that once I understand how to do this, it will get me far down the road in my understanding of ASP.NET programming. I have read all I can from "ASP.NET Programming Step-by-Step using Visual Basic .NET" and "ASP.NET Unleashed" but neither deals with this specific issue.
I will appreciate any (very specific) help given.