Put Autocomplete Methods In Separate Web File?

Dec 16, 2010

I have a web site with a growing number of AJAX calls.

I have AJAX code that looks like this:

function setupNameAutocomplete(id) {
$(id).autocomplete({
source: function(request, response) {
$.ajax({
url: "selectName.aspx/getNameAutocomplete",

Originally, the above javascript code was used on a web page where a user typed in the name of a person to search for; I decided I wanted to have autocomplete on the name.

However, as I continued to develop the web site, I decided that I wanted to be able to use the same "name" autocomplete on many pages. Logically, it made sense to put my javascript code in an external .js file instead of repeating it on every page.

It also makes sense that I would want to put the .net code that handles the AJAX in its own file as well. The .net autocomplete code looks like this:

[WebMethod]
public static IEnumerable<string> getNameAutocomplete(string text)
{
IEnumerable<string> values = lookupNamesThatStartWith(text);
return values;
}

Naturally, it seemed like this codes belongs in an external .asmx or perhaps a .ashx file, but I can't get my javascript code working unless I call the above code from selectName.aspx.

How can I get my AJAX .net code in a seperate code file?

View 1 Replies


Similar Messages:

DataSource Controls :: Display Results From Two Separate Tables In Two Separate Databases?

Jan 14, 2010

I have access to two seperate databases (mySQL) located on two servers. I need to get the data, link the tables on a key field and display the results in a datagrid. My challenge is that if the search criteria changes for the display it affects rows returned from on table and should thus automatically affect the linked table and resulting data returned.

what the best approach would be to achieving this? So far I have set up a dataset with a dataadapter and table for each connection and then linked the tables in the dataset. The problem that I'm having is getting the linked resultsets to work.

On my form I have the datagrid with two Objectdatasources one for each dataadapter and i believe that's where I'm going wrong...

View 1 Replies

How To Create A Log File As A Separate Class

May 13, 2010

I'm web dev newbie. I'm trying to create a log file as a separate class that will catch every exception , the thing is I don't much about files, where it is created, the path should be given or not, where is the ideal place to create it

View 3 Replies

Reading Settings From Separate Config File?

Feb 9, 2010

My asp.net app has is using a web.config for common configuration. I also have a section that maps some data objects to connection strings, and that section is going to be couple thousand of lines. I want to move that section to another config file "dataMappings.config", so I don't bulk up web.config - is there a standard mechanism of accessing that config file?

View 1 Replies

Read A Text File And Separate The Data

Feb 25, 2011

I want to read a text file and separate the data and write it back to another text file. So the input file content is like 07090000079011110225000 00001000100010118832 032111050111205011110501111022500000FL .... I know that first 3 characters are for CompanyID, next 2 are for Symbol etc. How Can I put it together? I used to write in VB code like this below using a Type and define the width there.(easy to maintain) How can I do that in VB.Net or c#?

[Code]....

So the output will be like CompanyID : 070 Symbol :90 .

View 8 Replies

Best Practices To Separate Resource File From Web Project?

Feb 14, 2011

I have a web application project which contains few resource file. i am planning to create another one project for Mobile where i should be able to use the same resource files.

some best practices to separate the resource files.

View 1 Replies

Web Forms :: How To Make The Separate Code File Work

Oct 21, 2010

I am using some code I found that generates a random password. I am in the habit of putting code in a seperate file. The code was written in the same file and I'm trying to move it to a seperate file and get the following message. Also, below, I posted
the original code (code on same page as aspx) and what I did (code in seperate file).what adjustment needs to be made to make the seperate code file work?

Compiler Error Message: BC31143: Method 'Public Function GeneratePassword(length As Integer, numberOfNonAlphanumericCharacters As Integer) As String' does not have a ignature compatible with delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'.

Source Error:

[Code]....

ORIGINAL CODE (with code on same page)

[Code]....

MY CODE BEHIND

[Code]....

[Code]....

View 2 Replies

Typed Configuration Data In A Separate Config File In 4.0?

Oct 24, 2010

I have an asp.net 4.0 web application.I need extensive configuration data for this web application, that is strongly typed and the structure of this configuration data is going to be fairly complex (cannot do with key-value pairs). In the past I remember having done this in .Net 2.0 but cannot figure out how I will do it in .Net 4.0. The class and config mapping is like shown below (really simplified for the purpose of illustration only):

class SettingsClass
{
int count;

[code]...

View 1 Replies

AJAX :: Creating Simple Autocomplete / Taking One Textbox Adding Autocomplete Extender?

Sep 29, 2010

I'm creating just simple autocomplete sample.

taking one textbox adding autocomplete extender as

<asp:ScriptManager ID="ScriptManager2" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server" EnableTheming="True" ></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" ServiceMethod="GetCountryInfo" ServicePath="WebService.asmx" TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

Also creating web services as "WebService.asmx" & code inside this file is that

<%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" %>

------

then in Webservice.cs file i write code as

public class WebService : System.Web.Services.WebService {
MySql.Data.MySqlClient.MySqlCommand cmd = new MySqlCommand();
MySql.Data.MySqlClient.MySqlConnection con = new MySqlConnection();
//MySqlDataAdapter da = new MySqlDataAdapter();
MySqlDataReader dr;
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 10;
string sql = "Select * from tbl_patientmaster Where P_NAME like '" + @prefixText + "%'";
con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["HMSDBConnectionString"].ToString();
con.Open();
MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, con);
da.SelectCommand.Parameters.Add("@prefixText", MySql.Data.MySqlClient.MySqlDbType.VarChar, 50).Value = prefixText + "%";
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (System.Data.DataRow dr in dt.Rows)
{
items.SetValue(dr["P_NAME"].ToString(), i);
i++;
}
return items;
}

this code is not working

View 1 Replies

Web Forms :: Calling Variable When Set In Separate Code File - Can't Work Out

Feb 8, 2011

I've done a search and read a few things, All i'm trying to do is set a variable in the code file and call it in the page file asp.net vb.net 3.5. I've tried like this in the code file:

[Code]....

And in the design part of the page:

[Code]....

But it says that name isn't declaired. What am I doing wrong?

View 7 Replies

C# - Adding And Maintaining Named Strings In A Separate Class File?

Aug 3, 2010

I have developed an asp.net web application containing 40-50 pages. I have implemented logger using Log4net and each of my pages has this in its page_load event.

[code]...

This method has many strings like "In page Load function","OrgId","Homepage.aspx?Sid=1","Page load function successfull". Now i would like to maintain these string which are common throughout my application in a seperate class file and use it with a variable...

View 2 Replies

MVC Dynamic Stylesheets - Parse As Separate File When It Doesn't Work

Aug 24, 2010

The project I'm working on allows an end-user to modify CSS code to integrate the application as best possible. Most of the CSS values are stored in a database and need to be retrieved and parsed dynamically. I setup a Style controller, and gave each stylesheet an action, and then passed the configuration data through to the View. I set the ContentType to "text/css" and then generated the stylesheets. This works fine, but the problem I'm running into is this: none of the code works in the application. I include it in the head code, but it doesn't parse in the code. An example of what I do is this:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" ContentType="text/css" %>
.element {
background-color: <%= ViewData.Model.BackgroundColor %>;
}

I include it like so:

<link href="/style/Basic" rel="stylesheet" type="text/css" media="all" />

When I include the CSS code in a partial view and include it using the ViewModel (wrapped in style tags) in an action, then everything works fine. It is when I try to parse this as a separate file when it does not work. Is there something I am doing incorrectly? Or is there some kind of glitch?

View 2 Replies

Configuration - Have Settings In The Web.config (and Access Them Using ConfigurationSection) Or In A Separate XML File?

Sep 20, 2010

I have few settings which I could place in a separate XML file and have them accessed in the Web app. Then I thought (thinking of one additional file to deploy), why not have them in the web.config itself. However, just because I need to have custom nodes, I can not have the settings under . So, I am thinking of creating a custom config handler following this. Would that be better than having a separate XML file? Is It going to be an overkill or performance wise? Is there a better way to go?

View 1 Replies

Visual Studio :: VWD 2010 - No Option To Allow Code To Be Placed In Separate File

Jan 2, 2011

This question has probably been answered before, when adding a new web form, I do not see an option that allows you to place code in a seperate file for a project (it does it automatically). But for websites, I see the option. Am I missing some option?

View 1 Replies

Web Forms :: Attach A Separate File Code Into Aspx Page?

Nov 8, 2010

I have a separate aspx Page called Home.aspx page and a separate class called class1.cs

I want to attach the class1 into Home.aspx

I try with this but not work

[Code]....

View 5 Replies

C# - Webclient Upload File Methods?

Nov 21, 2010

It seems that webclient supports PUT and POST uploading. Is there any difference?

View 1 Replies

C# - Loading A File From Page Methods?

Dec 7, 2010

I have a JavaScript function which calls a page method as follows:

function openFile(file) {
PageMethods.LoadFile(file);
}
[System.Web.Services.WebMethod]
public static void LoadFile(string fileName)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/binary";
var filePath = @"C:MyFiles" + fileName;
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename="{0}"", fileName));
HttpContext.Current.Response.WriteFile(filePath);
HttpContext.Current.Response.End();
}

The page method throws the following exception:

Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'LoadFile' failed with the following error: System.Threading.ThreadAbortException-- Thread was being aborted.

View 1 Replies

Web Forms :: In Html File Whole Page Is Displayed.. How To Separate Banner N Menu Bar

Dec 15, 2010

I created home page design / layout in photoshop (PSD file)

Converted to HTML file and will contains associated images folder

How can I use this html file in asp.net Master page?

* created ascx file to INCLUDE Banner , Menu Bar Buttons ( on the Banner it selves)

- In html file whole page is displayed.. how to separate Banner n menu bar?

* Is it useful to create ASCX file as whole banner,menu bar buttons n whole page design done n available in HTML format? Instead can we use that HTML file in Master Page?

* had only images of Menu Bar Buttons... Then I need to make it as Hyperlinks tonavigate to web pages... How to get links thru images which is already designed on Banner?

View 1 Replies

How To Make A Class Recognize That An Interface Found In A Separate File Exists

Mar 8, 2010

I've made an interface called ApprovalEvent in a separate file with the namespace myproject... I've also made a class called PurchaseOrder... it's also in the same namespace, just in a separate file. Whenever I try to make PurchaseOrder implement ApprovalEvent it always says that ApprovalEvent is undefined...

How can I make the class recognize that the interface exists but is in a different file?

Here's some code:

[Code]....

View 1 Replies

Forms Data Controls :: Moving 'postback Script' To A Separate Javascript File?

Jan 8, 2011

I'm writing few custom controls. The server controls inject javascript so that the postback can happen as everyone know.

Is there a solution to move this script to a seperate js file?

View 6 Replies

Using Extension Methods In Static Methods On Extended Classes?

Aug 16, 2010

I have an extension method as follows:

public static class PageExtensions
{
public static int GetUserId(this Page targetPage)
{
var user = Membership.GetUser(targetPage.User.Identity.Name);
return (int)user.ProviderUserKey;
}
}

Now in a page I need to use this method in a static WebMethod, so I have added another 'extension method' to PageExtensions:

public static int GetUserId()
{
return (int)Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;
}

and I call it as follows in my WebMethod: PageExtensions.GetUserId()

View 1 Replies

Web Forms :: How To Change This Methods In To Use Dictionary Or Extension Methods

Jul 23, 2010

public class CacheHelper { /// <summary> /// Removes object with the specified key. /// </summary> /// <param name="key">The key.</param> [code]....

I have this methods for caching..I need to change this methods to use in aDictionary<string,object>

How do I need to change this code Because I am new to asp.net I am still learning..

View 12 Replies

Web Forms :: Connection To Database From Local Visual Studio Not Working - Code In Separate File?

Mar 11, 2010

I recently started NOT putting code in separate file. I am using vb. I am having a problem with my database connection. The live code is working just fine....but when I try to debug locally. i get this error. connection to the database from my local visual studio is not working. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" %>
<script runat="server">
Const ConnectionString As String = "Data Source=1234.database.com;Initial Catalog=database_name;Persist Security Info=True;User =user_name;Password=123456"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MyConn As New Data.SqlClient.SqlConnection(ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand("Select count (*) from Classifieds where (ClassifiedCatagory = 'Antiques')", MyConn)
cmd.Connection.Open()
Dim count As Integer = cmd.ExecuteScalar() 'this contains the number of records
Label_Antiques.Text = count
cmd.Connection.Close()

View 4 Replies

Using JQuery AutoComplete Plugin - Submit On Autocomplete?

Feb 17, 2011

I'm using jQuery AutoComplete Plugin in ASP.Net as outlined in the article below, so that as a user types in a .Net textbox they get a list of options to choose them. This works fine, but what I need to do now is call a server side function when the user has finished typing or has choosen a value, rather than the user having to submit the value by pressing a button.

View 2 Replies

Can Fill An Dropdownlist Or Another Autocomplete On The Id Provided By Autocomplete

Aug 10, 2010

I am using Ajaxtoolkit 3.5.I am using an autocomplete textbox extender.My problem is I have populated Country in the autocomplete textbox.I have to populate city in another dr

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved