Autocomplete using Ajax - c#

I want to provide an autocomplete option for a text in my web applciation . I have the master data in the SQL server database table. I beowsed in google and found how to use autocomplte. all the examples use web service to do this. I cannot create a web service to impltement this. Is it possible to implement autocomplete by looking up values from database in code behind ? If so any one can provide any sample links for reference ?
Thanks in advance,
Jebli

It depends on the volume of data. There are 2 options:
send it to the client pre-emptively (perhaps as json or html) in the page source
let the client query it based on their input
The second is common if the data-volume is non-trivial, as you can query when (for example) they've entered 3 characters; very useful for names and other long lists.
Re the web-service; this doesn't have to be a full/complex web-service; just a simple route or ashx (for example) that returns the filtered data.
The jquery autocomplete plugin supports both scenarios, although this is now partly obsoleted by jquery ui plugin.
Is it possible to implement autocomplete by looking up values from database in code behind
Well, that is at the server - so you're essentially talking about the same "web service" that you say you can't do... I also think you should separate out the 2 functions (create page vs provide auto-complete results) into separate files (/pages/whatever).

A simple way would be to make a new aspx page that takes the autocomplete query as querystring parameters, looks up the result in a database and returns the response as XML og JSON.

Related

JQuery UI Modal Form Dialog Save Data To Database

I am using the JQuery UI Modal Form Dialog and trying to save the old data and new data to a database. I am using C# (backend) and ASP.NET front end. I can delete new entries, I just don't know how to save the data. I have tried searching ways to pull pull the HTML data in, but couldn't get rid of the errors. Also Wasn't sure if there was a better method? Here is my JSFiddle
function addUser() {
I need to figure out a way to get the data from the table and post it to the server.
I think what you may be looking for is web methods, it allows the jquery (client side) to call the backend (c#) and for them to interact with each other.
Check out this link for reference:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Here is a brief summary from the website:
When it comes to lightweight client-side communication, I’ve noticed
that many of you prefer ASP.NET AJAX’s page methods to full ASMX web
services. In fact, page methods came up in the very first comment on
my article about using jQuery to consume ASMX web services. Given
their popularity, I’d like to give them their due attention. As a
result of Justin‘s question in those comments, I discovered that you
can call page methods via jQuery. In fact, it turns out that you can
even do it without involving the ScriptManager at all. In this post, I
will clarify exactly what is and isn’t necessary in order to use page
methods. Then, I’ll show you how to use jQuery to call a page method
without using the ScriptManager.
I found this:
This script gets data from the table that you can then parse through.
You could then pass it into a hidden field.

Search engine optimization for database loaded using jQuery

I am currently optimizing my site for search engines. It is mainly a database driven site. I am using C# on the back end but database content is loaded via jQuery ajax and a web service. Therefore, my database content is not in html at the point that the bots will crawl it. My site is kind of like an online supermarket format in that there are thousands of items in my database, users can load a single one of these or more onto the web page at a time and the page does not change significantly once items are loaded.
My question is, how (if at all) can I get my database contents indexed? I was thinking of having an anchor that links to an aspx page (eg called mydatabase) which loads all of my database items as a big html list. Then, using jQuery, I would make the anchor invisible to users. The data would still be accessible to users but not by this link, it would be accessed by using the jQuery interface I have created.
The thing is, I don't really want users to see this big, messy list - would google results show this page eg www.mysite.com/mydatabase.aspx as a search result? Also would google see this as "keyword rich" spam page? I have done quite a lot of research but found nothing on this. only instructions for php. Please help I'm not sure what to do and need to know the best way to go about this.
It's a shame you haven't taken the progressive enhancement approach as it would mean you would have started with a standard HTML output that's crawlable, and then adding the layering behaviour (AJAX) on top for the user experience.
Providing a single file (e.g. mydatabase.aspx) that lists all of your products in a list format provides no real value for the reason you gave - it would just be a big useless list. No editorial content relevance for each link etc.
You're much better off taking another look at your information architecture and trying ensure that each product is accessibile by it's own unique URL, then classifying the products into groups (result pages), being careful to think about pagination.
You can still make this act like a single-page application using AJAX, but you'd want to look into HTML5's History API to achieve this in a search engine friendly way.

How to develop a Query Refinement tool using C# / Asp.Net

Want to develop a query refinement tool just like Google Suggest so that i will get recommended options when i enter keywords in the search textbox i.e( if i type "car"
i will get the recommended options as rental cars,used cars,cars for sale etc) want to develop the tool in c#/ASP.Net dont know where to start.please give some suggestions.
This can be achieved by using javascript and let's say some web service / page method. You send the values that user gave you to a web service. The web service translates the text, make some database (or other storage) request and return the results to the page as json (or some other format that suits you).
Look at this article if you need some example code:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=515
By the way, if you need more articles, just put "asp.net autocomplete" into Google. That should give you plenty of resources.

Localizing JavaScript strings in an ASP.NET Web Forms application

One of the apps I work on is a large ASP.NET 3.5 Web Forms app that is used in the U.S., Central and South Americas, and Europe. We're also starting to do more work with AJAX, and thus we need to settle on a strategy for localizing strings in our JavaScript controls.
For example, we have a control written as a jQuery plugin that formats data into a sortable table. The buttons and table columns need to be localizable.
We're currently using two different approaches to handle this scenario, but I'm not completely satisfied with either.
Write the bulk of the code in a jQuery plugin style, then place a script block on the .aspx page where we'll pull in values from a .resx file and feed them into the plugin code. Here's an example in pseudo code:
<script>
var view;
$(function() {
view = {
columnHeaders: {
productNumber = <%$ Resources:WidgetProductNumber_HeaderText %>,
productDescription = <%$ Resources:WidgetProductDescription_HeaderText %>
}
};
});
</script>
Place the JavaScript in plain .js files with custom tokens in place of strings. We have a handrolled HttpModule that will parse JavaScript files and replace the tokens with values from any existing .resx file whose file name matches the name of the JavaScript file being processed.
Both approaches have problems. I'd prefer to keep our JavaScript code separate from our .aspx pages to make it more unobtrusive and reusable.
The HttpModule approach is clever but a little opaque to developers. I'm also looking to implement a JavaScript bundler called Rejuicer, which is also written as an HttpModule, and getting these to work together seems like it would require customizing the open source code. I'd prefer to use the code as it's written so that we can upgrade it as the project progresses.
Are there any other tried-and-true strategies for approaching this problem in ASP.NET?
It seems that both approaches are a little more complex/cumbersome than necessary. Keep it simple.
1) Using an .ashx, custom http handler, or web service, create a .net object (anonymous, custom -- doesn't matter) that matches the client side JSON object.
2) Populate server side object's properties with the localized values
3) Set the response content type to text/json or text/javascript.
4) Using the JavaScriptSerializer class, serialize the object into the response stream.
From the client side, you have two options:
1) Use an AJAX call to the .ashx/handler/service to set your client side "view" object to the response JSON.
2) Create a script tag with the src="the/path/to/the/serviceOrHandler". In this case you would need to include the js variable declaration in your response output.
Let me know if you need a code sample.
I just stumbled onto this question, and I have another answer to throw into the ring. It isn't my work or anything, but it looks like a fairly elegant solution. It involves writing a localization handler to serve up ASP.NET resources to Javascript. Here are a couple of links:
http://weblog.west-wind.com/posts/2009/Apr/02/A-Localization-Handler-to-serve-ASPNET-Resources-to-JavaScript
http://www.tikalk.com/use-aspnet-resource-strings-within-javascript-files/

How to call a Web Page an automatically fill up a Form passing a String

I use asp.net 4 c sharp.
I would like populate a input text form with a string sent by an User.
The destination page is:
http://www.maxmind.com/app/locate_demo_ip
NOTE: im not the developer for the target page.
Here ho should work:
When a visitor from my site click a link (Ip address)
it will be sent to: http://www.maxmind.com/app/locate_demo_ip
and the TextBox automatically populates with the value (Ip address the user has clicked).
The user Will manually click the button "Look Up IP addresses" in maxmind.com to have the result.
Any idea how to do it? Maybe a sample of code?
Thanks guys as usual for your great support! :-)
if you can, generate a link with this form :
http://www.maxmind.com/app/locate_demo_ip?ip=XX.XX.XX.XX
then, the page can access this value using txt1.Text = Page.Request.QueryString["ip"]
[Edit] it assumes that you are the developer of the target page... is it ?
You tells me you are not the developper.
Either maxmind provide an url syntax similar to the one below (check if there is an api section, or you will have to inject with javascript the value. In this case, you have to know :
for security reason, to avoid a cross site scripting attack, you can't pilot an external site from one page to the other. You can maybe add your application in the trusted zone of the client computer, but it's not possible in an internet application
nothing guaranties that the html structure of maxmind won't change in the future. you can't rely on this.
An another approach would be to "proxy" the features of maxmin by calling yourself from your server application the target page, with a Http Post request. Then you can parse the results to use it on your application. Again, some limitations are to consider :
maxmind may disallow such calls. They may want the user to use their application
again, the target page may change its structure and the textbox names
parsing the result can give headache... and the output structure may change (again)
you have to handle yourself the UI related to this feature.
A final though : what is your goal ? maybe there are other ways to achieve it.

Categories