473,287 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Postback Events Not Raised

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
Nov 18 '05 #1
3 3444
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

Nov 18 '05 #2
Ken,

Sorry about taking so long to get back to you. I've checked that your code
works and am working on putting together a sample based on it that
illustrates the problem I'm having. I'll post it probably over the next day
or two. Thanks for your help!

"Ken Cox [Microsoft MVP]" wrote:
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

Nov 18 '05 #3
Hi Mark,

Thanks for your followup. If you have any further questions or need any
assistance, please feel free to post here or open a new thread in this
group.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Luner | last post by:
I am having problem postback, (code shown below) the variable "my_str" is lost after clicking the "submit" button. Isn't it suppose to display "changed" after posting back? Is there anyway I...
5
by: Dan | last post by:
Hi, I'd like to find out the control that caused a postback to be raised. Obviously this could simply done in a control event handler. I am not going to do this method and would like no...
5
by: George Durzi | last post by:
I have a simple user control with a text box and a submit button. When the user enters some text into the textbox and clicks the submit button, a record is created in the database. I'm using...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
9
by: Joe | last post by:
I have a DataGrid with a templated column that displays ImageButtons. I need to know if one of these buttons caused the postback or just another button on the form. If one of these buttons caused...
8
by: MattB | last post by:
I have a form with multiple text boxes on it and one of several can raise a postback event. Is there a way to easily tell which one raised the event? Thanks! Matt
5
by: Daniel | last post by:
Hey guys When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire; You need to also unsubscribe it to avoid a resource leak so that the object it is in gets garbage collected like so...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
3
by: ronchese | last post by:
Hello. I wrote a Web Custom Control that have a property named SelectedValue. This SelectedValue property is set after the user clicks a LinkButton control, by its Click() event. I did some...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.