Click here to Skip to main content
16,006,341 members
Articles / All Topics
Technical Blog

Why My Event is Not Firing on Click of Controls

Rate me:
Please Sign up or sign in to vote.
4.00/5 (3 votes)
27 Oct 2013CPOL2 min read 7.4K   2   2
Some insights into why my event is not firing on click of controls

Many a times, it happens that we get stuck on issues for hours and later we realize how stupid that problem was. My aim in this blog is to cater to these kinds of issues only. There is nothing new that you will learn here. But it might happen you are also stuck with some similar problem and it will help you get out of the struggle.

“Why the hell my event is not firing when I have done everything right”……. Classic problem which I have faced many times in my early days and now I find new guys babbling about the same. Most of the time, the culprit is the Page Load event. After all, this event is heavily bombarded with calls to many initializations, methods, events, binding and God knows what. Just look for the following traps:

  1. Look out for “if(!Page.IsPostBack)
    Aahha, you missed that, right? Whether you are clicking a button inside gridview, listview, tracking selection change of combobox/dropdown, radiobuttons list, checkbox list, etc. if you do not have your binding code under this small condition, your control will bind again, and make you feel you wasted your efforts put in binding those controls. Sounds easy, but many a times we do miss this out.

  2. Are your variables globally defined and initialized/assigned?
    Stupid, but happens. We do define and assign variable values inside a loop and expect it to behave normally outside its reach. So cross check the reach of your variables.

  3. Query string parameters are misbehaving while the parent page passed them correctly?
    If you feel everything is right, check out whether your parameters contains character ‘&’ (ampersand). Now this is a killer. Wherever this character comes, it will break apart the parameters and will present you text after that as a new parameter. For example, if your query string is like
    http://abcd.com?id=2&name=Jhonson&Jhonson&type=baby”.
    Now when you will try to find the value of parameter name, you will find value as “Jhonson” and not “Jhonson&Jhonson”. Make sure you “HttpUtility.UrlEncode” your URL or replace ‘&’ by %26 in the URL.

  4. When event is firing still your control is getting reset, this might help. Check by mistake “EnableViewState” is not set as “false” for the control or its parent controls. Sounds silly, but sometimes happens when you copy paste from somewhere. :)

The post Why my event is not firing on click of controls appeared first on Clear your dot net issues.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Enziq Solutions Pvt. Ltd.
India India
My key portfolios at Enziq Solutions includes Business Development and Strategy and overseeing Technology operations.
Read more about me at: http://enziq.com/site/Company/mangesh.html or http://mangeshdevikar.enziq.com/about-me/

Comments and Discussions

 
QuestionEvent Not working on Check Box Pin
Work - Dedication - Attitude13-Nov-13 20:35
Work - Dedication - Attitude13-Nov-13 20:35 
In an asp.net page two one asp panel and have some asp controls inside it. so all the page controls are inside in update panel. i have one check box above my panel, when i click on check box first it is working fine. but when i binned all the controls with some value on that event then all the controls not shown its binned value and the above check box event is working only when check box is checked other wise event not fire. find me the good solution and what the actually problem happens in it.

i hope you will give me a good solution as early.Thumbs Up | :thumbsup:
Rohit Arora
Software Developer

AnswerRe: Event Not working on Check Box Pin
Mangesh V. Devikar14-Nov-13 19:57
professionalMangesh V. Devikar14-Nov-13 19:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.