Wednesday, March 28, 2012

calling a VB class from Javascript?

Hi, I created a webservice to return a dataset for my autocomplete word list. Now, I am wondering if it's possible that we could call a vb class in javascript function? Eg.

HTML:<inputtype="text"onkeypress="return getList(this);"id="strSearch"/>

Javascript: function getList(word) { // call or invoke vb class to return dataset }

If that is impossible, is there anyway to create a autocomplete WITHOUT using XMLHTTP ..?

Take a look at pagemethods with the script manager.


I think you can use Async Postback. Take a look athttp://forums.asp.net/t/1168088.aspx

Let me know if it answers your question.

Thanks


Unless you remote script it in an iframe, whatever you do with AJAX is going to use XmlHttpRequest. Why do you want to avoid that?

Page methods might work well for what you're doing, though you'd need to convert your DataSet to an array before returning it. The AJAX framework doesn't support serializing DataSets to JSON quite yet (soon).

However, if all you want is an auto completing TextBox, you should just take a look at theAutoComplete extender in the AJAX Toolkit. No point in re-inventing the wheel.


No, JavaScript can not call a function that is serverside code. It can only call JavaScript code. If you want to call code on the server, you should ook into using the pagemethod,http://forums.asp.net/t/1175553.aspx:

For more infomation, seehttp://www.asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx, especially the following section:

Calling Static Methods in an ASP.NET Web Page

You can add static page methods to an ASP.NET page and qualify them as Web methods. You can then call these methods from script as if they were part of a Web service, but without creating a separate .asmx file. To create Web methods in a page, import theSystem.Web.Services namespace and add aWebMethodAttribute attribute to each static method that you want to expose.

To be able to call static page methods as Web methods, you must set theEnablePageMethods attribute of theScriptManager control totrue.

The following example shows how to call static page methods from the client script to write and read session-state values.

RunView

Best Regards,

No comments:

Post a Comment