473,327 Members | 2,074 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,327 software developers and data experts.

Event Handler is not called for Control inside User Control

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
2 2298
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tamir Khason | last post by:
I build user control, consists of different things (e.g label, image, etc.) I want to handle click (and other) events, however I can not do it until I do not assign event handler for each control...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
1
by: David Veeneman | last post by:
I am writing a control that relies on its host to validate the contents of one of its fields. The control fires a custom 'FooNeedsValidating' event and passes the field's data with the event. The...
4
by: VMI | last post by:
My aspx has a user Control (a .ascx) that includes all the fields of an address (add1, city, st, etc...). How can I add an event handler to a comboBox inside the .ascx from within my aspx page? I...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
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...
4
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.