Update listbox in c# sql - c#

Currently I created a wizard with a listbox. The listbox has a next and previous button. The listbox has thousands of items but the next and previous will show them 30 items at a time.
I am not using AJAX so the page reloads each time the button is being clicked. I don't want the page to reload everytime the user clicks next and previous. I thought of using AJAX.
Is there anyway I can prevent the page from reloading either by AJAX or a different way everytime the user presses next. Pressing next triggers a stored procedure which selects the next 30 items.
C#, SQL, ASP.NET, HTML, JavaScript

You can surely use jquery for this purpose. It will allow you to do an ajax request. In fact, ajax request can be done from a .Net page with even plain javascript and it has nothing to do with .Net version.
However, using jquery will make it easy and you will be able to easily populate the listbox using the results from server.

Related

asp.net backspace key press repeat previous postback

I am new to .NET and can use some help. I have been working on a VB6 database client side frontend with mySql backend for years. Now I am moving to .NET 4.0 Web server side frontend with C#.
I just started on my first data entry page. I have a listbox for a Sql dataset from db. User click an item in the list to load the record tags into bunch of textboxes, ddls, gridview, and table for editing. Most things worked so far as I wanted, but I just found a weird thing. After loading a record from the list, I double clicked a textbox which is set to read-only and disabled, the content is highlighted, then I hit the backspace key (by accident actually), the previous postback action was performed (which is to load the records into the listbox and clear all controls for record tages).
How do I prevent this from happening? Thanks.

Postback versus Javascript Clientside Calculations

I have an ASP.NET web app I'm developing but I have a question concerning efficiency. On my page I have Textboxes that have an OnTextChange event that calls a C# page with the function inside. The function works and sums up some values and sends the output back to the page. Now the function is only called if some event triggers a Postback to the server then the calculations are done. I'm wondering if I use both server-side code and some Javascript to do the same calculations would there be a conflict in data when the Postback occurs? For example If I'm submitting the data to a SQL database would there be any sort of issue? Javascript is immediate at doing simple math and would be a better UI for the user to have instant results when punching in some numbers to the textbox, without having to press enter or a submit button.
You shouldn't worry about this. Whatever you do in Javascript will post back correctly to the server. You will not see any kind of "conflicts".

c# ASP.NET Persistant Data even with page refresh

I have a asp.net page with c# code behind. I have a first panel where the user selects and enters information, they then click continue and that data is stored in variable. A new panel displays on screen and the select some new data which when they click continue stores that data in that panel and sends all the information to a c# program. The problem I an getting is that when I click continue the first time and the page refreshing showing only the new panel all the data defaults to 0. How can I fix this?
Thanks
HTML is a connectionless protocol. This means there is no state. There are ways to mimic state with .net, but html has no means of this by default. If you are using webforms, you can utilize viewstate as long as you are posting back to the same page each time. If you are using mvc, you will either have to submit your data via ajax or you will have to send all the initial data you sent to the server back to the view so when you press continue you can populate it all again. Or just use jQuery/javascript to hide(), show() portions of your page, but wait till everything is completed prior to posting to the server.
Good luck

ASP page get current focused control

So what I have is a bunch of dynamically created textboxs that when the user enters some data and either tabs out or clicks out some calculations are done. After the page posts back control focus is lost. What I need is to be able to set focus back to the control that was tabbed to or clicked into not the control that data was entered into.
You'll have to send information about that control in the post. What happens in a postback is the the browser completely discards the current DOM and loads a brand new one, so to keep your place you'll have to tell your server where your place was and have javascript code that runs on page load to put things back.
Other options include doing this either entirely in javascript or using an ajax partial postback.

What can cause a page to lose its viewstate when doing a browser back?

I have a page which the user gets shown when he wants to create a new or edit an existing document. There are two UserControls on the page. One simple DatePicker and a more complex grid. After filling out or editing the data he then can press continue which brings him to the review page where he can decide to really create or update the document or go back and change something. Going back is done in javascript with a history.back()
Now when the user is in "new" mode and decides to go back from the review page the grid partially looses its viewstate and the DatePicker loses it completly.
On the other hand when the user is in "edit" mode and goes back from the review page both controls maintain their viewstate.
I know that the browser just shows the cached version of the "new/edit" page. But why the difference in the state of the controls and what can I do so that it works in both cases?
Viewstate is essentially a hidden field in the form that gets populated with the control values that have been posted back to the server.
If a user enters or selects some values in the form's controls, performs a postback and then presses the browser's back button or does a javascript history.back(), you are viewing the page as it was before the postback took place. Therefore, the choices made by the user prior to the postback will not be present on the page.
The difference between "new" and "edit" is that on "edit" you are retrieving information from the database to populate the controls.
Instead of doing javascript history.back(), you should look into using a Wizard control. The wizard control is designed for this very purpose. If the user enters information in multiple steps, goes to the review page and needs to go back a step or all the way back to the first step everything is maintained in Viewstate.

Categories