473,385 Members | 1,912 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,385 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 3450
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.