Event/postback cycle in dropdown - asp.net

I know this might be an easy question but still:
I got a dropdown and a button on my website, autopostback is false on the dropdown and I use the "SelectedIndexChanged" event. When I pick an item from the dropdown nothing happens ofcoure, but when I click the button, the system somehow knows that the index has changed in the dropdown and it calls the SelectedIndexChanged event, where does it store this information?
Im guessing the events are being added to a list and then fired upon postback

The original state of the DDL is stored in viewstate. Upon postback, the new state and old state are compared and the event fired (or not) accordingly

Related

Selecting an item from a listbox fires a prerender event that removes the focus from it

I am creating an ASP.net application. I fill a ListBox control with items and I use the PreRender event of the Listbox to set its width according to the largest item in the control.
But after the ListBox is rendered, the first time I click an item in the ListBox the PreRender event fires and focus is removed from the ListBox (this event fires unnecessarily because the ListBox is already rendered). The second time I click on an item in ListBox the PreRender event doesnt fire and focus is maintained.
Is this behaviour normal? What could cause this behaviour?
The ListBox is filled on PageLoad if is not postback, with a default value.
The Listbox is filled on the TextChanged event of a TextBox (the TextBox is used for searching in a DB)
EDIT:
I commented out the PreRender event and the behaviour is not gone. Now I am thinking this may be caused by a PostBack from the TextBox when I remove the focus from it and select an item from the ListBox.
The evidence to this regard: I have a gif that is shown between the beginning and end of a request from the TextBox (loading indicator) and the gif is visible when I select an item from the ListBox for the first time after a render. The second time there is no problem.
Use the AutoPostBack property to specify whether an automatic postback to the server will occur when the TextBox control loses focus. Pressing the ENTER or the TAB key while in the TextBox control is the most common way to change focus.
I have found out why the behaviour I reported happens. Can I somehow make the TextBox not to postback on losing focus? It is aleady posting back on TextChanged and it is enough.
Use the AutoPostBack property to specify whether an automatic postback to the server will occur when the TextBox control loses focus. Pressing the ENTER or the TAB key while in the TextBox control is the most common way to change focus.
I have found out why the behaviour I reported happens. I will now search how to stop the autopostoback on losing focus.

Can I fire button click event without firing pageload event?

I have a button on my page and and few textboxes which alters their context on page_load event. when I open the page for the first time it loads random data from a database to textboxes with a function in pageload and also I create those textboxes dynamically. what I want is to make some changes on textboxes texts and click the button than send new context of textboxes to database. But when I click on button, PageLoad event fires again and It regenerates the textboxes and the context of them alter naturally since they are newly created textboxes. I tried to use "if(!Page.isPostBack)" in pageload but then the textboxes and related objects are not being created and they become null.
how can I overcome this problem?
best thing I can think of is to find some way to fire buttons click event without firing PageLoad event, but I dont know how can I do it.
any help would be appreciated;)
From Comments
Can you regenerate the Textbox on each Page load Execution? and data assignment to these Textbox should be under !Page.IsPostback. All you have to do is to keep the IDs of the Textbox in ViewState only first time page load and next regeneration of Textbox will have the previous stored ID and you also have to store the ID corresponding data in ViewState. Makes sense?

OnCheckChanged triggered multiple times for CheckBox in repeater in updatepanel

I've got a repeater in an update panel. the contents of the repeater is refreshed every 5 secs.
(AsyncPostBackTrigger bound to the tick event of a timer)
In every item of the repeater there's a checkbox with autopostback set to true.
I want the state of each checkbox to be preserved after each refresh of the repeater, that's why I save it's state in Page.Session. And then in the tick event handler I set the Checked value of the Checkbox to the value from the session. Unfortunately, this seems to trigger the OnCheckedChanged event and thus I do not know anymore which event handler invocation comes from user interaction and which from code.
Anybody knows why the OnCheckChanged is triggered more than once and how can I
prevent the extra occurencies? Is there a way to prevent the AsyncPostBackTrigger from triggering the OnCheckedChanged event of the Checkbox?
You can find out which control caused the post back by checking Page.Request.Params.Get("__EVENTTARGET"), which returns the ID of the control. However...
I won't know for sure without reading your code, but you shouldn't need to worry about tracking which checkboxes are checked, the checked state should be saved in viewstate (unless you have it turned off...) So if this isn't the case there is probably something else wrong with your page.

autopackback dropdownlist only if changed using mouse

I would like to perform a postback when the droplistlist selected value changes, but only if it was changed via expanding the downdown and clicking an option, not is the user tabs to the control and uses the arrow keys. The reason for this is simple, keyboard accessibility.
Postbacks are triggered using __doPostBack('uniqueidofcontrol', 'commandname'); so when the list changes value (I believe in onchange event), it posts to the server. You would need to not set autopostback. What you would need to do is tap into the click event (if there is one) and then call __doPostBack(..) method upon that event.
HTH.

DropDownList doesn't postback on SelectedIndexChanged

I'm writing an ASP.Net webform with some DropDownList controls on it. Then user changes selected item in one of dropdowns, ASP.Net doesn't seem to handle SelectedIndexChanged event until form is submitted with a 'Submit' button click.
How do I make my dropdowns handle SelectedIndexChanged instantly?
P.S. It's a classic question I have answered too many times, but it seems no one asked it before on stackoverflow.
Setting the AutoPostback property to true will cause it to postback when the selection is changed. Please note that this requires javascript to be enabled.
You need to set the AutoPostBack property of the list to true.
Also, if you're populating the contents of the drop down list from the code behind (getting the contents of the list from a database, for example) - make sure you're not re-binding the data in every postback.
Sometimes people are caught out by binding the drop-down in the page load event without putting it in an If Not IsPostBack. This will cause the event not to fire.
The same is also true of repeaters and ItemCommand events.
if you are populating the dropdown list during page load then each time the page postback it will reload the list thus negating your postback method.
you need to be sure to load the dropdownlist only if (!ispostback)
Set the AutoPostBack property of DropDownList to true.

Resources