I am showing some information on mouse hovering on the links. I am doing this by making an AJAX call on mouse hover the the links and fetching the data from database.
Problem is that if I mouse hover several times on the same link it will make the AJAX call and hit the database in each time. But I want if it once fetch the data from the database for a specific link on second time mouse hover it should not hit the database again. For this I need to store the data in client side some where and reuse it(I think).
What is the best approach to handle this situation? Can any one suggest me the solutions?
P.S: I am having more than 20 such links in the page.
use the One function, it guarantees that the call gets executed once.
You could store the information in a hidden field or fields. On the first request, just check if the requested info is already available in there, and if not, hit the database.
May this will be a wrong way but you can do this in this way:
Define class attribute for the anchor tag and change the class to true to false after loading data from database when someone click this link again check the class name what it indicates true or false in this way you can do
<a class="load-true"></a>
after loading data
<a class="load-false"></a>
and check class to load data.
thanks
on the JavaScript side, use a hash table where the keys correspond to the IDs of links that have been hovered. You only call the DB when inserting a new key (as in allHovers[curHover]++; ) A side benefit of this is that you would have a list & count of hovers that you can reference at any time.
Related
I am making a basic ticketing system in C# with basic coding experience. Most of my experience is in SQL.
I have the database and tables. I have stored procedures to create and amend tickets.
I am stuck (this is probably very basic) because:
On my EDIT ticket page, I populate various text boxes and drop downs from my existing data via inline SQL.
On my page, I can edit all the fields and dropdowns with new values. (i.e. change a ticket priority from when it was first logged)
I have a button, that calls my "update" stored procedure, however it updates only the NEW fields I have, any amendments to the existing fields are overwritten by the original values before submitting.
The original values are called on pageload, so I think the button reloads the page before submitting. I want it to submit all the values that are on the screen.
I think this must be something obvious, remember I am a novice so I may have missed something simple.
If what you're saying is you load values from the DB into the form controls in the PageLoad event handler, then yes, you're probably overwriting the changed values. To keep things as simple as possible for you, wrap the original values loading code in the following:
if( !IsPostBack )
{
// load initial form values here from DB
}
I'd suggest you read about the ASP.NET page lifecycle: http://msdn.microsoft.com/en-us/library/ms178472(v=vs.90).aspx
i am working on a asp.net web app in this application when customer logged in then his/her
personal details displayed in form fields (e.g. full name in name box ,age in age box etc) for getting data first i fetch the data from ms sql then assign them to ICustomer interface properties this interface is implemented by customer class.
And we also have a update button on customer information page so if without changing any information if a user click on update then unnecessary it will go to server and come back and the same data updated in database,so what i am trying to do is to just detect whether something changed in customer form then only update functionality should work.
i have two option
just use Java script and detected the text change then unable update button.
make a temporary reference of ICustomer and compare it to the older when then process by making something true or false.
so please suggest me the best approach for it or any other method.
if question is unclear then just comment on it i will explain more.
If you're using the formview or detailsview control in your asp.net webpage, then you can use the OldValues property of the forms's itemupdating event to compare the values before posting to your database. I believe the form's viewstate must be enabled for this to work.
protected void myFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
// Access the old values
e.OldValues...
Here's a full example using the detailsview.
JavaScript may help you, but it's very unreliable. I say go with the second option. Store the ICustomer object in a Session variable and compare it with the new one.
If you're using TextBox controls, one option is to use the TextChanged event to detect changes.
You should go to 2nd option if the size of your object is not very large as you have to store the old object before comparing to the new object of Icustomer to detect any changes. Otherwise use javascript to detect the changes on the text fields. but as you know its not very much reliable.
the main problem with the Javascript option is that what if user changes value and again change to it's previous state in that case also it'll shows value changed.
I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.
I have an ASP.NET page where at the top of the page is a search box. There are 2 text boxes - one is an autocomplete extender for the Name on a database, and one is just inputting the ID.
The page features DetailsViews and GridViews primarily, and even when no account has been searched for, these display blank data which is not ideal. I sort of fixed this by using if (IsPostBack), encasing the elements in a placeholder and setting it to visible only if the page ispostback. But this doesn't cover if the user types in an incorrect ID.
Also, some accounts have huge amounts of data inside the GridView's. I had an issue where because I have no way of detecting when a data source's rows has changed, I end up binding whenever the page loads (Page_Load method). I've come to realise this is simply very bad - there are lots of times when the user can click various things in the page and have the page postback, and it takes an eternity to load each time I click something for accounts with lots of data.
Anyway, my question is essentially two-fold but I have a feeling the solution will be similar:
1: How can I detect when there are no accounts returned when searching, and disable the Grids/Detailsviews and show an error message?
2: How can I figure out when the user searches for another account and only rebind the grids after that has happened?
Thanks
This method is very ugly but it'll get the work done.
1) To Check whether there are no records; after the AutoComplete Extenders Webservice is called if no record is returned put some value in Session like
Session["NoData"]=true;
if Records are found then;
Session["NoData"]=false;
after the webservice is called do ajax request to check that session & on the basis of value do what you want.
2) You can achieve this also by following the above option.
I have the following scenario I would like to implement.
I have a number of drop downs that the client can select a range of criteria. From this, they will press a button, the query will be generated and low and behold, a gridview will be produced in a new window (or at least give that impression) bound by an object datasource. I would also like the user to be able to amend the search numerous times so they can generate a number of new windows/gridviews.
Now then..what would be the best approach for achieving this result?
My initial thinking was to create a querystring generated by the client criteria selections (in the drop down lists), a new page would then take the querystring and populate the gridview here. My concern with this approach is that the query string could be a whopper...are there any disadvantages to creating a ridiculously long query string?
Alternatively, are there any other methods or ideas people have used to produce a similar desired effect?
Any suggests taken on board and all advice warmly received.
There is nothing wrong with a long querystring; it is just not as clean or as easy to use as Jeroen's session-object solution. Save the session object value:
Session("ObjectName") = variablename
Retrieve it:
variablename = Session("ObjectName")
The only reason to use a querystring is if you don't want the session data hanging around, though I can't imagine why that would be an issue.
You could handle the button's Click event and store the variables you need in Session object.
In the newly opened window with your gridview you take those values and assign them to the proper parameters in your ObjectDataSource's Selecting event.