473,756 Members | 6,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2321
cc*********@gma il.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
29073
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 inside me user contol. Is there way to do this "smart" just inherit all possible events from usercontrol class instead of rewriting custom handlers for each control inside ??? Thankx
2
17031
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 the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
12
4140
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. However in vb.net you get continual messages (even setting the system modal property). Firstly, are these two assumptions right and if so what is the approved
41
4319
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 on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
1
5256
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 host handles the event, validates the data and returns the validation results to the control by a callback to a control method, SetFooError(). All of that works great. If the host returns false on the validation, I display an error glyph next to...
4
22196
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 just want to add this event handler to that instance of the comboBox. Thanks.
9
2471
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 post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
2
3929
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 well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever possible to make the app more efficient and less resource demanding. On one page there are 2...
4
237
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: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.