Event Handler is not called for Control inside User Control

C

ccbalapatel

Hi,
We have recently converted our code to ASP.NET 2.0. We have an user
control that is embedded inside the page. The user control has a link
button and the event handler for the link button is written inside the
user control. When the link button is clicked, the page is posted back
and the page_load method of the user control also executes fine. But,
the event handler for the link button is not called. The same code
works fine on ASP.NET 1.1. After some research into this problem, I
have figured out that the link button's UniqueId is not matching with
the __EVENTTARGET parameter and hence the event handler is not
triggered.

This seems to be a bug in Microsoft ASP.NET framework. Does anyone
have any workarounds for this problem? Our code is kind of complicated
with multiple user controls on the same page and all these user
controls are derived from a base UserControl which contains properties
common to all the user controls on the page. Moving the event handler
to the page (from the control) might not work.

Thanks in advance.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Hi,
We have recently converted our code to ASP.NET 2.0. We have an user
control that is embedded inside the page. The user control has a link
button and the event handler for the link button is written inside the
user control. When the link button is clicked, the page is posted back
and the page_load method of the user control also executes fine. But,
the event handler for the link button is not called. The same code
works fine on ASP.NET 1.1. After some research into this problem, I
have figured out that the link button's UniqueId is not matching with
the __EVENTTARGET parameter and hence the event handler is not
triggered.

This seems to be a bug in Microsoft ASP.NET framework. Does anyone
have any workarounds for this problem? Our code is kind of complicated
with multiple user controls on the same page and all these user
controls are derived from a base UserControl which contains properties
common to all the user controls on the page. Moving the event handler
to the page (from the control) might not work.

Thanks in advance.

Funny how the first conclusion is that it's a bug in the framework, that
has been tested by thousands or even millions of people, rather in your
own code, that has been tested by a single person... ;)

Event handlers works just fine in user controls. I just placed two link
buttons in a user control and tested that the Click even really works,
you to be really sure that it does work in the exact case that you are
describing.

If the UniqueId of the control doesn't match what's used in the
postback, the id of the control has changed, either during the process
of creating the first page, or from the first to the second page creation.

If you for example add controls dynamically to the page, and don't set a
specific id on the user control (so that it gets an automatic name like
ctl07), it's id may change if you don't add the exact same controls each
time. The same also applies to any control that is a naming container,
so even if you set an id on the user control, but put it in a container
without a specific id, the id of the user control may change.
 
C

ccbalapatel

Does the applications tested by thousands have no bugs?

Anyway, you are right about the simple user control scenario. After
some testing with a simple page and a simple user control, I have
realized that the event handler inside the control works. The problem
I describe is similar to that of http://www.thescripts.com/forum/thread320245.html.

The reason I came to that conclusion was because the same code works
in 1.1. I think I need to take a closer look at the page and the
controls and see why it is not working in 2.0. Obviously, there seems
to be a difference in the way how these things are handled between 1.1
and 2.0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top