Javascript not working when added masterpage

Posted by Amritha444 under C# on 7/1/2013 | Points: 10 | Views : 2461 | Status : [Member] | Replies : 2
hi all Im tring to do Jquery autocomplete textbox with multiple words separated by comma .I got source code from this blog
But when tried to add master page to this page javascript not working or autofill not appearing.can anyone point out my mistake

<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function () {
function SearchText() {
source: function (request, response) {
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/GetAutoCompleteData",
data: "{'username':'" + extractLast(request.term) + "'}",
dataType: "json",
success: function (data) {
error: function (result) {
focus: function () {
// prevent value inserted on focus
return false;
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
// add the selected item
// add placeholder to get the comma-and-space at the end
this.value = terms.join(", ");
return false;
$("#txtSearch").bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete") {
function split(val) {
return val.split(/,\s*/);
function extractLast(term) {
return split(term).pop();
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<div class="demo">
<div class="ui-widget">
<label for="tbAuto">Enter UserName: </label>
<%--<input type="text" id="txtSearch" />--%>
<asp:TextBox ID="txtSearch" runat="server" Width="300px"></asp:TextBox>

Thanks in Advance

thanks and regards


Posted by: Raj.Trivedi on: 7/1/2013 [Member] [MVP] Starter | Points: 25

Hello Amritha,

Where is your textbox in the Master page or in the Content Page.

If the textbox is in content page and if you kept the reference in master page and wrote the function in master page and if you are trying to call the Jquery Search text method on the content page then it will not work becuase the master page can only give you common look and feel.

You can either keep the textbox in master page where you have written the javascript or write the javascript in the page where the textbox is.

"Sharing is Caring"
Please mark as answer if your Query is resolved

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 7/2/2013 [Member] [MVP] Starter | Points: 25

Hi Amritha,
As your code is correct, you have to access your txtSearch with following code-

or you use jquery selector to access your textbox and mention i jquery autofill:true, refer below link for more information.

Hope you are clear.

Jitendra Kumar
If my post helps you, plz mark as an answer.

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response