By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,960 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,960 IT Pros & Developers. It's quick & easy.

Event Handler is not called for Control inside User Control

P: n/a
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.

Apr 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
cc*********@gmail.com wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Apr 4 '07 #2

P: n/a
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.
Apr 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.