I am developing using VSTS 2008 + C# + .Net 3.5 + ASP.Net. I am new to jQuery and ASP.Net AJAX framework. Suppose I need to use jQuery function (e.g. from jquery-1.3.2.js). I want to confirm that jQuery and ASP.Net AJAX framework are totally two different things, no dependencies?
So, no need to install and configure ASP.Net AJAX framework in order to use jQuery function?
thanks in advance,
George
Yes you are correct. You don't need both to function. You can find information on the AJAX toolkit here. You might also find JqueryUI quite useful. I'm quite new to Jquery as well and found JqueryUI to be quite a time saver. If you want, you can also let Google host Jquery and/or JqueryUI for you, so your bandwidth doesn't get taken up (Info here). Just to add, if you want intellisense with your Jquery code, this blog shows you how to setup VS2008 to do so.
Related
I have a button
<input type="submit" value="Click Me" onclick="substitute()"/>
In one of my first HTML5 pages. Is there anyway I can write the body of the substitute method in C# code?
Or is it that I have no other option other than JavaScript?
The only way to have C# respond to a web page is to POST the page to a web server, or execute an AJAX request. On the web server side, your request will execute some method that contains C# code.
But it really depends on what you are trying to do; some things are better handled in the browser. Study up on ASP.NET MVC and Javascript, and your strategy will become clearer.
There are some tools that you can use to write code in C# that will be run in the browser. However this requires automatic translation of C# into JavaScript (as only JS is supported by all browsers). This maybe useful if you want to share code in C# between your Desktop app and Web app. The drawback is that any error on the page will be in the auto-generated JavaScript and you will have to somehow map this to your C# code, which may be hard.
Take a look on:
JSIL
Saltarelle
You can find more information in the Miguel de Icaza blog post:
http://tirania.org/blog/archive/2012/Sep-06.html
Like an alternative, I can offer you to look on
TypeScript which is JavaScript language's superscript, with the syntax comfortable for C# developers made by Microsoft.
Very interesting and promising project, but still in active development, as far as I know, so keep an I on regressions and retrocompatibility, if you decide to you use it.
Hope this helps.
I have successfully downloaded and installed AJAX framework, and the control toolkit.
While trying to insert any AJAX controls such as UpdatePanels or ScriptManagers into an existent ASP.NET Web Site (which currently has no AJAX functionalities) I get the following error:
"Attempret do read or write protected memory. This is often an indicator that other memory is corrupt."
So as a test, I've created a brand new project, as an ASP.NET AJAX-Enabled Web Site, as follows:
And in the default page of this project there is an ScriptManager already, and I've been able to insert an UpdatePanel, do a little test with a label and a button updating its content to the current time.
The question is: What does an "ASP.NET AJAX-Enabled Web Site" have that an "ASP.NET Web Site" does not that prevents me from adding AJAX controls ?
Do you have more than one version of the AJAX libraries. Often times, the versions can be different between what you have set to use in the configuration file and the controls you are slapping on the page. That is the first place I would check.
You also need to make sure you have the correct version of both AJAX and the control library. This can be you downloaded an old control kit and are using the latest .NET framework, as much of the AJAX functionality has been included in .NET 4.0. Or it can be downloading newer bits and trying to use them with 2.0.
As far as I remember (it's been a while since I used AjaxControlToolkit) this error occurs when you attempt to modify the response stream from your code behind (ie: perform a Response.Write(); , or Response.End(); etc etc...
if the method your AsyncPostback trigger is calling is doing any kind of response stream modification then comment it out and try it again as a "proof of concept"..
hopefully this gets you going on the right track.
Dave
How do I go about making true ajax requests to an asp.net page? (Not update panels). I read this tutorial but couldn't get it working. Is there a better approach? Or should this work?
http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
The standard today is using JSON to get the job done. That means you'll be using JavaScript, and when you're using JavaScript jQuery is your friend.
Here's some example code that uses AJAX, jQuery, and a .NET Web Service. Learn it, love it, live it.
Try PageMethods. It will be easier. You're living in a .NET world, use the .NET tools.
Here's a page to get you started.
http://aspalliance.com/1922
I was reading an article that shows how bad CodePlex uses UpdatePanels and how nice is StackOverflow on this matter when, for example, a user upvotes an answer/question.
I wonder if someone can point a tutorial on how to do such action.
I know some points:
Create a Web Service that gets the action value and ouputs a JSON string
Build the javascript inside <ajax:ScripManager> control to replace the correct value on the page with the new value
But, even in the first I have difficulties, I can send a JSON string, but it will always be surrounded with XML information!
Can anyone (or maybe Jeff) point to a nice "how-to" since scratch? Thank you.
Well, I doubt StackOverflow uses UpdatePanel - more likely it uses jQuery / load to simply update a div, using ASP.NET MVC as the source (rather than ASP.NET vanilla, which has a more complex page cycle).
With this approach, it is trivial... the jQuery examples tab largely says it all.
Re returning the Json - that is simply return Json(obj); from the controller in ASP.NET MVC - but personally I'd return the html (simpler).
Before you dismiss the UpdatePanel I suggest you have a read of this post I did - http://www.aaron-powell.com/blog/august-2008/optimising-updatepanels.aspx. It looks at how to optimise UpdatePanels and it can lead to some performance increases if done well.
I also did a post - http://www.aaron-powell.com/blog/august-2008/paging-data-client-side.aspx which looks at doing client-side templating with jQuery and MS AJAX. I look at how to read a web service with JavaScript and if you download the sample you'll see how to send data client-side to a web service.
But this video cast on the ASP.NET website may also be of use - http://www.asp.net/learn/ajax-videos/video-82.aspx. It's on how to extend web services for script service capabilities.
how do i make an autocomplete textbox in asp?
but i need to get the autocomplete data by querying the database.
I dont really know how to explain this, sory if theres not enough detail.
i cant use ajax, because i think i will have compability issues with my old app.
so im thinking of doing this using java script. or is there a way to do this by using .net?
im using C# for codebehind. thanks
It's going to be a lot of effort without using some third party autocomplete I think - not sure what you mean by 'I can't use ajax', but how about using the ASP.NET AJAX autocomplete control, setting the ServiceMethod property to a static Page Method in your code behind? That keeps it contained within your page at least.
The Page Method can go off to your database, and return a String[] of results.
If you decide to use it, you'll need to set the EnablePageMethods property to true in the <asp:ScriptManager> control.
AJAX is JavaScript. It's JavaScript using the XMLHttpRequest object to make the asynchronous request. Here's an article about it and ASP.NET.
If you want to know more about AJAX, (Asynchronous JavaScript and XML), I'd check out Wikipedia first. If you want books on it, there are a ton. I recommend Programming ASP.NET AJAX by Christian Wenz (O'Reilly And Associates).
if you dont want to uses ajax library, try jquery
there are many plugin autocomplete or suggest textbox for jquery
try this one
http://www.vulgarisoip.com/2007/08/06/jquerysuggest-11/
The ASP.NET AJAX framework works for ASP.NET 2.0 & above. As such it will not work in Visual Studio 2003 environment.
Anthem.NET is a free, cross-browser AJAX toolkit/framework for the ASP.NET development environment that works with both ASP.NET 1.1 and 2.0 -
http://sourceforge.net/projects/anthem-dot-net
For your autocomplete requirement, you can consider using the jQuery Autocomplete Plugin
It requires very less programming. Check the demo & code sample here - http://docs.jquery.com/Plugins/Autocomplete
It's autocomplete() method takes a URL or array to populate your autocompletion list. You can pass the URL of the page that fetches the results from the database directly.