.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Event bubbling - Mousehover event for child controls

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :Windows Application


I have a form and some controls inside it.

I want to fire an event when user enter the form and when he leaves the form .

this.MouseEnter += (sender, e) =>
   //do stuff

this.MouseLeave += (sender, e) =>
   //do stuff

the problem with that is when I move mouse over the child control, form's mouseleave event is triggered.

I don't want this to happen (even if the mouse over control is still over the form).


How to solve that?

I don't want to set any events on the children (because there are many controls and some of them create dynamically).

I also don't want to use any timers to check the position....

I know I can use IMessageFilter, and add to application:

 Application.AddMessageFilter(new MyMessageFilter());
 public bool PreFilterMessage(ref Message m)
if (m.Msg == 0x2a1) { }
But this will fire for entire application and not just for one form, and I don;t know how to detect inside PreFilterMessage the current control.



View Complete Post

More Related Resource Links

Event bubbling

The article Event bubbling was added by xiii on Wednesday, June 02, 2010.

Server controls like Datagrid, DataList, Repeater can have other child controls insidethem. Example DataGrid can have combo box inside datagrid. These child control do notraise there events by themselves, rather they pass the event to the container parent

Adding client event handlers to an ASP.NET controls programmatically



I want to add client event handlers to ASP.NET controls (For example: GridView/Button ) programmatically to ASP.NET.

I am aware of "onclick" event handler, so my code would be

GridView1.Attributes.Add("onclick", "JSGridViewFunction()");

Button1.Attributes.Add("onclick", "JSButtonFunction()");

I want to know what are all the event handlers that are available for (or that can be added to)  ASP.NET controls.

For example, I want to add "onsort" event handler to ASP.NET GridView control.

But the following code fails

GridView1.Attributes.Add("onsort", "JSGridViewFunction()");

Please help.


Generated controls - skipping focus event - C# + JS


Ok, here is my senario.

A random (6-15) amount of textboxes are generated. Each textbox represents only one character. From those textboxes, three of them (at a random position) are enabled and the rest disabled.


When I put a character in any enabled textbox, it must put the focus on the next enabled textbox.


Textbox IDs go from 'char0' to 'char15' OR 'char0' to 'char12' OR ...

All the textboxes are generated so I can't set up specific focus events for each textbox because the designated control is unknown at design time.

Here is my attempt:


<script type="text/javascript">
    function abc(nextfocus)


for (int i = 0; i < focusableControls.Length-1; i++)
focusableControls[i].ClientSideEvents.KeyDown = "abc(" + focusableControls[i + 1].ID + ")";


focusableControls is an array with all the textboxes in that can get focus. It is also in the right order.

Things I want to find out:

How will I send the textbox out of focus

SPUtility.TransferToErrorPage("My Message") not allowed to attach any controls event.

Hi, I have created a custom error page and update it using to webApplication using following code: WebApplication.UpdateMappedPage(SPWebApplicaton.SPCustomPage.Error, CustomErrorPage) My error page contains one link button and onClick event, I have to perform some operations. As I click on the button Error is occurred and onClick event code didn't execute. If I render custom error page by providing url in IE like http://myweburl/_layouts/myerrorpage then every thing is working fine i.e. every event is working fine. Also If I use SPUtility.Redirect() method instead of SPUtility.TransferToErrorPage() then also every thing is working fine. My error message is as follow in case of SPUtility.TransferToErrorPage(): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. StackTrace is [HttpException (0x80004005): Unable to validate data.]    System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +10988853    System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +295 [ViewStateException: Invalid viewstate. Client IP: fe80::8960:150e:cf5d:2e17%11 Port: 53192 User-Agent: Mozill

Cant stop MouseDoubleClick Event from bubbling in treeview


I have assigned an event handler for  mousedoubleclick on treeviewitems in a style. However, after the eventhandler has finished executing for the treeviewitem that i double clicked, it runs again for all its parent nodes right to the top of the tree. I have specified e.Handled = true at the end of the event handler but it doesnt seem to have any effect.

I have included the full code below. The treeview is made up of different object types, and therefore i have a different HierarchicalDataTemplate for each of these types (maybe thats the problem).

Anyway, i would like to know of a way to stop the event from bubbling up so the MouseDoubleClick event is only handled for the treeviewitem i double clicked

Sorry for the amount of code i had to provide to demonstrate the problem, but this has been nagging me for days!


Classes i am using:

using System; 

TextBox in UserControl: "TextChanged" event does not see other controls


I am building a UserControl with several TextBox controls. The behavior I'm looking for, is everytime a value is changed in any TextBox, the UserControl refreshes a couple labels contained within it. Here's the code behind file that does the work:

Public Sub Refresh(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
    lblTotalHours.Content = txtHours.Text
End Sub

Now, here's a way to hook it up that works, however, "PreviewTextInput" gives the old textbox value to Refresh() and not the new one (as expected). I'm just writing this example because I had to confirm that my method of linking the event worked - and it does. My application runs fine even though the result isn't what I am looking for: (edit: to make it work, i also adapted the Refresh() declaration to match the PreviewTextInput delegate to TextCompositionEventArgs, if I recall correctly...)

<UserControl ...>
        <Style TargetType="x:Key TextBox">
            <EventSetter Event="PreviewTextInput" Handler="Refresh" />
        <TextBox Name=&q

Click Event from template child


I Created a custom control Which then got a child of which i also declared the template


  <Style x:Key="{x:Type local:ToolMenu}" TargetType="{x:Type local:ToolMenu}">
    <Setter Property="Template">
        <ControlTemplate TargetType="{x:T

How to disable the controls within the JQGrid on some other event



I am trying to disable the controls within the JQGrid on some other event. Please let me know how can i do this. Below is my JQGrid Basically i want to disable the custom buttons btnDeleteExistingRoles, btnAddExistingRoles and the checkboxes that are created in the "Select" column( i have written a custom formatter for this). Please help

jQuery(document).ready(function() {

    $('#btnHdnExistingRoles').click(function() {
        var lastsel2;
        jQuery("#grdExistingRoles").jqGrid({ url: '/SAPWebAccess/Role.mvc/GetExistingRoleForUser/',
            datatype: 'json', mtype: 'GET',
            colNames: ['Role ID', "<input type='checkbox' id = 'headerCheck' onclick='checkAll(\"grdExistingRole\");'>", 'Role Name', 'Role Text', 'Valid From'

How to create event handlers for Composite Controls



How to create event handlers for Composite Controls. I have created a composite control with label, textbox and button. Like this

        public TextBox txt1 = new TextBox();
        public Label lbl1 = new Label();
        public Button btn1 = new Button();

protected override void CreateChildControls()



Now how to write the code once a event fires like text changed or click.



ASP.NET validation controls are removing client event handlers.


 Below is a tiny section of code to highlight a problem that I am currently having. The textbox has an onblur event (the workings of the onblur event are irrelevant), and an associated RequiredFieldValidator. This code functions exactly as it should. However, if in the body onload event I simply raise an alert of the innerHTML of tr1 or td1, the onblur event does not appear (but it does work, and can be seen when I view source in IE7). If I remove the RequiredFieldValidator, the onblur event handler is shown in the alert, or if I retain the validator but change onblur to onfocus, then the event handler also appears in the alert. I need this to work as when the user increases the Quantity, duplicates of the table row are added (I have tried both cloneNode, and setting the innerHTML of each new table cell to that of the original, but as my alert proves, the onblur event handler is not included in what is copied). The same problem also occurs with onchange for select tags with validators. I am using Visual Studio 2008 (.Net 2), IE7 and IIS 7.

<tr id="tr1" /> 
  <td id="td1" />Quantity <input id="txtQuantity" onblur="fnBlur(this)" type="text" maxlength="2" value="1" runat="server" />   
 <asp:RequiredFieldValidator id="reqQuantity"

Button onclick event not firing when some AJAX controls are introduced



I have a web page which has both asp.net controls as well as AJAX controls.I am facing a weird issue when I introduce some AJAX controls(Modal popup) inside a tabbed panel, the button onClick event stops firing.Can anyone suggest what might be the reason for this?

Here is my code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Entity.aspx.cs" Inherits="Entity" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderImagePlaceHolder" Runat="Server">
<img src="images/image5.jpg" alt="NewsPageImage" />
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager_TabContainer" runat="server">
      <asp:TabContainer ID="TabContainer_Metadata" runat=&q

Dynamic hyperlink controls in button click event


Hi, i am creating a visual webpart in which when button is clicked dynamically hyperlinks must be displayed

In my senario i am having textbox,button,repeater control,when i enter url in textbox and click the button,hyperlink must be dynamically created and displayed in repeater control

i am not able to do this

thank you


ListView Control, MouseUp event fires twice, once MouseUp and then on MouseHover.


Greetings all,

using: VS2010, Frwk 4.0, Windows7 Ultimate N.

When the ListView's MultiSelect property is set to False, MouseUp is fired twice with one click.

The event is fired when the mouse button is up (which is normal), but then fired again when you move the mouse.

This bug has been reported in Microsoft Connect on June 29 2005,  here... and reported fixed. Its not.


Is there any kind of workaround for this?


thanks in advance for suggestions/ideas here.


bind event handler for dynamic controls in repeater



I am faceing following problem


I have a repeater control on a modal popup extender. On run time I add linkbutton based on the number of items in a datatable assigned to that repeater control.In itemDataBound event of repeater I am adding that link button, like this


if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                LinkButton lbtn = new LinkButton();
                lbtn.ID = "lbtn" + DataBinder.Eval(e.Item.DataItem, "DatasourceId").ToString();
                lbtn.Text = DataBinder.Eval(e.Item.DataItem, "DatasourceName").ToString();

                lbtn.Click += new EventHandler(lbtn_Click);



but this linkbutton event is not getting fired on click. only the modal popup goes off.

I tried with command also for linkbutton instead of Click event handler. But that also did not help.


Propagate child event to a parent control in a user control

I developed a user control with using a picturebox and a label in .net.  Then I create an instance of the user control in a form. Here I wish to add an click event handler for that user control. I want to use only one click event handler for that control not for every controls (eg: picturebox ,label). Even an user click on a label ,picturebox or the form container, an UserControl_click event will be fired. How can I accomplish this?

Radio Button Event

Here I have explained the events of radio button with javascript.
Let me explain the scenarion first,
We are having two radio button say radioobtn1 and radiobtn2. If I click on the button 1 then I need to show one DIVor FORM. same as when I click on radiobtn 2. I have given the code for the above scenarion.

how to impose javascript event processing?


If I have some form control like textbox and I want the event handler to be located in the html instead of at the server side, how to do that? Of course I can copy paste javascript code in the aspx file. But is it possible to do that using some object oriented approach (ie programmatically in the code behind)?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend