Hi Mark,
Not sure if this is what you are after, but I wonder if you are digging deep
enough to assign the event handler for the button. I put the code in
page.aspx but have to go through a couple of hoops (actually user controls)
to get a reference to the button.
Anyway, the code that I came up with below works, but maybe doesn't do what
you want. Let us know if it helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
' page.aspx
<%@ Page Language="VB" %>
<%@ Register TagPrefix="uc0" TagName="Module" Src="Module.ascx" %>
<script runat="server">
Sub Page_Load
dim usr1 as usercontrol
dim usr2 as usercontrol
dim btn as button
usr1=page.findcontrol("UserControl1")
if not isnothing(usr1) then
usr2=usr1.findcontrol("UserControl1")
if not isnothing(usr2) then
btn=usr2.findcontrol("Button1")
if not isnothing(btn) then
AddHandler btn.click, AddressOf ButtonClick
end if
end if
end if
End sub
Sub ButtonClick(sender As Object, e As System.EventArgs)
dim btn as button
btn=ctype(sender,button)
response.write(btn.commandargument)
End sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<uc0:Module id="UserControl1" runat="server"></uc0:Module>
</p>
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
<!-- Insert content here -->
</p>
</form>
</body>
</html>
' Module.ascx
<%@ Control Language="VB" %>
<%@ Register TagPrefix="uc0" TagName="ProblemHere" Src="ProblemHere.ascx" %>
<uc0:ProblemHere id="UserControl1" runat="server"></uc0:ProblemHere>
' ProblemHere.ascx
<%@ Control Language="VB" %>
<asp:Button id="Button1" CommandName="ButtonClicked"
CommandArgument="WasClicked" runat="server" Text="Button"></asp:Button>
"Solel Software" wrote:
Hi,
I have a user control embedded in another user control that is embedded in a
web form
Page.aspx < Module.ascx < ProblemHere.ascx
In ProblemHere.ascx I have a regular <asp:Button and a <asp:LinkButton and
am attempting to raise the Command event when one or both are clicked.
Unfortunately the Command event is not being raised on postback even though
the event handler is wired up. The Page_Load event is raised when either is
clicked and when I debugged Page_Load I found that __EVENTTARGET contains the
ID of the LinkButton when it posts back, so that seems to be working
correctly. I even put the event handler wire up in the Button's and
LinkButton's declaration:
<asp:Button onCommand="btnUpdate_Command"
but that didn't help. Does anyone know why the page would post back and
raise Page_Load but not the Command event? I don't have any Repeaters or
DataBind commands that would erase it on postback either and EnableViewState
= True. Any help would be appreciated! Thanks!
--
Sincerely,
Mark Fox