通过javascript webservice不会使用母版页面触发 [英] through javascript webservice does not fired using master page
本文介绍了通过javascript webservice不会使用母版页面触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用webservice通过ajax自动完成扩展程序在文本框中获取名称但是当我通过母版页调用web服务时它没有被解雇,我也在我的页面上使用了脚本管理器并且已经给出了srvice路径,但仍然没有工作
这是我的Web服务方法
I have used webservice to fetch name in textbox through ajax autocomplete extender but when i call web service through master page itz not gets fired ,i also have used script manager on my page and had given srvice path , but still itz not working
this is my Web service method
[WebMethod]
//[System.Web.Script.Services.ScriptMethod]
public string[] GetAutoCompleteData(string username)
{
SqlConnection con = new SqlConnection("Server=172.16.0.3;Database=CallRegister;User ID=Swati;Password=swa@123");
con.Open();
string strQuery="select DISTINCT name from HrMaster where name LIKE '%'+@SearchText+'%'";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strQuery,con);
da.Fill(ds);
con.Close();
List<string> cityList = new List<string>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
cityList.Add(ds.Tables[0].Rows[i][0].ToString());
}
return cityList.ToArray();
}
}
这是我的aspx页面
this is my aspx page
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.Master" CodeBehind="WebAjax.aspx.cs" Inherits="ERPOrganization.WebAjax" %>
<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="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$("#txtSearch").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoComplete.asmx/GetAutoCompleteData",
data: "{'username':'" + extractLast(request.term) + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
},
focus: function () {
// prevent value inserted on focus
return false;
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
});
$("#txtSearch").bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active) {
event.preventDefault();
}
})
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<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>
</div>
<%-- <cc1:AutoCompleteExtender ID="ac1" runat="server" ServiceMethod="GetCode" MinimumPrefixLength="1"
DelimiterCharacters="," TargetControlID="txtAssign" CompletionListCssClass="AutoExtender"
CompletionListItemCssClass="AutoExtenderList" ShowOnlyCurrentWordInCompletionListItem="true"
CompletionListHighlightedItemCssClass
="AutoExtenderHighlight"
Enabled="true" FirstRowSelected="true" EnableCaching="true"
CompletionSetCount="1" CompletionInterval="1000" CompletionListElementID="listPlacement1">
</cc1:AutoCompleteExtender>--%>
</asp:Content>
推荐答案
( document )。ready( function (){
SearchText();
});
function SearchText(){
(document).ready(function () { SearchText(); }); function SearchText() {
( #txtSearch)。autocomplete({
source: function (request,response){
("#txtSearch").autocomplete({ source: function (request, response) {
.ajax({
type: POST,
contentType: application / json; charset = utf-8,
url: AutoComplete.asmx / GetAutoCompleteData,
data: {'username':' + extractLast(request.term)+ '},
dataType: json,
成功: function (data){
响应(data.d);
},
错误: function (结果){
alert( 错误);
}
});
},
焦点:功能(){
// 阻止在焦点上插入值
return false < /跨度>;
},
select: function (event,ui){
var terms = split( this .value);
// 删除当前输入
terms.pop();
// 添加所选项目
terms.push(ui.item。值);
// 添加占位符以获取末尾的逗号和空格
terms.push( );
this .value = terms.join( ,);
return false ;
}
});
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "AutoComplete.asmx/GetAutoCompleteData", data: "{'username':'" + extractLast(request.term) + "'}", dataType: "json", success: function (data) { response(data.d); }, error: function (result) { alert("Error"); } }); }, focus: function () { // prevent value inserted on focus return false; }, select: function (event, ui) { var terms = split(this.value); // remove the current input terms.pop(); // add the selected item terms.push(ui.item.value); // add placeholder to get the comma-and-space at the end terms.push(""); this.value = terms.join(", "); return false; } });
这篇关于通过javascript webservice不会使用母版页面触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文