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:
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.
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.
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.
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.