Refreshing ListBox outside an update panel - asp.net

In my application, I have a list box(list of stores), Add and Remove buttons and another list box (selected stores).
I have Following requirements:
1. On click of Add button, copy selected items from the master stores list to the selected store list and clear the selection from master store list.
2. On Click of Remove button, remove the selected stores from the selected stores list.
I have added my master store list box and selected store list boxes to 2 different update panels and added triggers for each of the update panel. Things are working fine but one thing I have observed that it is taking unusually long to move selected stores from master list to selected list. I have around 5000 entries in the master list of stores.
If I remove the update panel for master store list, things are normal but I am not able to clear the selection. Am I doing something wrong? Is there a way to clear selection of listbox outside the update panel.

It sounds like your using UpdatePanels to move ListItems between 2 ListBox controls. This creates a overhead as each time you trigger the 'add' event it has to postback and render the UpdatePanel again (including the viewstate).
Have you looked into using jQuery to move your list items between your ListBox controls thus all the moving between boxes is handled by the browser. This will speed up the experience for the user?
You should also be able to use jQuery to clear the selection. If you can provide me a little snippet of your markup I can help you get it written up (or shoot me a message).
Brian =)

Related

Dynamics365 details master pattern, always loading first record, how to tell when the new button is pressed?

Using the Details Master pattern. When the form initially loads it shows a grid. When clicking on the grid the details are displayed, and is working perfectly fine. The issue with this design pattern is the first record is always loaded so when I look at the cursor the first record is showing.
I'm populating a two list view controls through code (one is available items and the second is selected with buttons to move the items back and forth between the controls) and my issue is when I press "New" the detail page is displayed but the list view is populated for the first record selected. I need a way to know when "New" is pressed I can clear out the list view selected control and just populate the available values.
I ended going a different direction and creating my own "New" button that calls a menu item to call a new form as a popup similar to how the form when entering a new customer works. Then I turned off the "New" button and now my code works fine without have to deal with the one screen containing both forms logic.

Create Dynamic Controls using retrieved data [Asp - Vb .Net]

I'm trying to create multiple controls by using retrieved data from query, but preventing them from dissapearing on postback, allowing me to get and mantain their values, the problem I have is that I cannot create them on Init because the number of controls, their IDs, and other properties are only known after user selects an item on menu.
Page loads a Menu with all its items and values (Data dependent), plus, a button is loaded too
User clicks a item on menu.
Selected value is used to perform a query by using a Dataset (This happens inside a function which is called from Menu_ItemClick event).
Retrieved data from query is used to determine how many controls must be created (2, 4, 6, etc.). Each control has its unique ID, which is given according to data.
Controls are created and placed into a Panel (named p).
Now controls are visible and available for editing (RadioButtons, TextAreas)
User clicks on button to save information from dynamic controls into a Database
Problems I'm facing
Controls dissapear on postback when clicking button, because they weren't created on Init.
Placing button on UpdatePanel to prevent whole page postback, makes dynamic controls not accesible when trying this:
For Each c In p.Controls
...
Next
The only control it gets is a single Literal control (Controls count is 1), as if other controls didn't exist.
Thank you in advance.
When you wrote "Controls dissapear on postback when clicking button, because they weren't created on Init", did you mean to say that "Controls dissapear on postback when clicking button, because they weren't re-created on Init"? If not, then that is likely a root cause of your problem - dynamically-created controls must always be recreated in response to a PostBack (cf. ASP.NET dynamically created controls and Postback). There may be other issues as well, as dynamic controls in Web Forms can provide a lot of challenges as your scenario gets more involved - here's one article that lays out many of them under various scenarios http://www.singingeels.com/Articles/Dynamically_Created_Controls_in_ASPNET.aspx (e.g., if the user can re-select from the DropDownList to generate a different set of dynamic controls). The canonical reference on all of this is http://msdn.microsoft.com/en-us/library/ms178472.aspx.
Now, on PostBack you'll need some way to ascertain which controls were dynamically created so they can be dynamically re-created. As such, you'll need to store somewhere whatever information allowed you to dynamically create the controls. Since ViewState isn't available in Page_Init and there can be other issues introduced when using sessions, my suggestion is to simply declare a HiddenField that contains that state information. In Page_Init, you'll then need to get the HiddenField's value from Request.Form (since the value of your HiddenField won't be loaded until after Page_Init from ViewState) and go from there to re-create your controls.
My final suggestion: try getting everything working with a regular Panel first and then try and introduce the UpdatePanel - no need to over-complicate the problem at first.

jqGrid ASP.NET Parent Row Selection and Child Edit Issue

I am attempting to use jqGrid ASP.NET for the first time and I'm having an issue with properly using a parent and child grid on my form.
Scenario: On my form I have two grids, one a parent that displays product information, and a second child grid that is used for editing a collection of prices for the product in the parent row. When a user clicks the plus sign in a parent row, the OnDataRequesting event is handled and I load the child grid with that product's prices. When the user clicks a price in the child grid, I use ClientSideEvents RowSelect and the server side RowEditing event to perform inline editing.
All of this was fairly trivial to set up and works great. Where I'm having an issue is that I'd like the selected row in the parent grid to act like a context for the rest of the page, i.e. the rest of the page displays information related to the product selected (charts, graphs, etc). For this I set up an event handler for the OnRowSelecting event and then trap the RowKey from the event args. That works great. However... the unintended side effect of setting up that handler is that once a user selects a row in the child grid to edit, the OnRowSelecting event fires in the parent, the page posts back, and when the page reloads the child grid is closed and the attempted edit is thwarted.
What I would like to know is, is there any built in way to handle this sort of scenario either through the client side jqGrid library or the Trirand.Web library? Or will I need to write some custom script to either send the selected parent row asynchronously or possibly trap the expanded child grid and attempt to reopen it once the post back is complete? Thanks.
I thought I'd brush off the tumbleweeds here and inject the answer I finally received from Trirand's support. As of the time of this writing, you can't do this. If you handle the OnRowSelecting event, you cannot use an editable child grid as they built it to specifically fire the parent's OnRowSelecting event anytime you select a row in a child grid.

jquery: populating a select list from an autocomplete?

The basic problem: selecting a few items from a list of thousands.
The potential solution:
I have an autocomplete field that searches the db, and returns a name/id pair. This is working fine.
The next step is to preserve the selected IDs, and allow the user to remove some if needed. For this, I've been looking at using a select, and was hoping a UI something like that provided by this, but it doesn't work: it allows you to select items that already exist in the select, but doesn't work with a dynamically created select.
The final step is a traditional postback (using a submit button, this is in asp.net webforms) where I'll need to have access to the final list of IDs.
Are there other options for this?
Based on your comments below, there are a lot of ways to skin this cat. The following approach is similar to the SelectList idea only it doesn't use a dropdown list. The nice thing about the Listbox versus the DropdownList is that the user will be able to view many items at once. Of course, the choice of using a Listbox or a DropdownList doesn't really matter as they both essentially provide the same functionality. The key about this answer is that values are stored on the client until you're ready to submit.
Create an autocomplete textbox that dynamically fills a Listbox as you type.
Clicking on a Listbox item results in two things happeing:
The ID of the selected item is stored in a client-side array
A list of items are rendered/re-rendered on the page exactly like the SelectList. Clicking the red 'X' will remove the ID from the array and re-render the list. You'll have to do a bit of jQuery coding on your side but it isn't much.
The above steps are repeated until the user has selected all of their items.
Upon clicking "Save", only the selected items are submitted to the server for processsing.

Can't find dynamic controls in datagrid on postback

Using .NET 1.1, I have a DataGrid that contains three columns for each row.
Row one has a label with some text.
Row three will always have two radio buttons and two checkboxes and those are in the HTML side of the page.
Row two will have dynamically generated controls (just textboxes for now) and there can be 1 or more per row. These will be used for user input.
There is a button on the page and when the user clicks the button I need to update the DataGrid’s source (my DataTable) with the new values from the user’s input.
The issue is the DataGrid seems to be losing the dynamically generated controls on PostBack. I can loop through each Item in the DataGrid and I can access the radio buttons and the checkboxes, but the textboxes aren’t there.
Any ideas?
Remember: every time a postback occurs you are working with a new instance of your page class. Dynamic controls added to the page during a previous postback went to the garbage collector as soon as the page for that postback rendered to the browser, along with the rest of that page instance. You need to re-create your dynamic controls on every postback.
you have to regenerate the controls. You should be able to get their values from the http request object

Resources