Tuesday, 17 September 2013

Code for AJAX TEXTCHANGE WEBSERVICE CALL



----------------.aspx--------------

   <script language="javascript" type="text/javascript">
       
    function CallParametersPageMethod()
    {
       Branch_Abrv = document.getElementById('txt_search').value;
       CommonWebService.Mai_Login_Branch(Branch_Abrv,onSucceeded,onFailed);
// CommonWebService ? WEBSERVICE NAME
// Mai_Login_Branch ? METHOD NAME FROM WEBSERVICE
    }

    function onSucceeded(result,userContext,methodName)
    {
        if(result!="")
        {
          document.getElementById('txt_search').value= result;
        }   
    }
    function onFailed(error,userContext,methodName)
    {
      alert("An error occurred");
    }

    </script>


.ASPX

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference InlineScript="true" Path="~/webservices/CommonWebService.asmx" />
</Services>
</asp:ScriptManager>


<asp:TextBox ID="txt_search" runat="server" Style="z-index: 112; left: 145px; position: absolute;
top: 135px;" TabIndex="4" ToolTip="Type Branch Name" AutoCompleteType="Disabled"
Width="143px"></asp:TextBox>


.CS CODE

txt_search.Attributes.Add("onblur", "javascript:return CallParametersPageMethod()");

.WEBSERVICES

[WebMethod]
public string Mai_Login_Branch(string prefixText)
{
if (prefixText.Contains("{") || prefixText.Contains("}"))
{
string[] branch_name = prefixText.Split('{');
prefixText = Convert.ToString(branch_name[1]).Trim();
prefixText = prefixText.Replace("{", "");
prefixText = prefixText.Replace("}", "");
}
sqlcnGPTERP = new SqlConnection(css.ConnectionString);
string sql = "select branch,branch_abrv,pk_branch_key from Branch Where branch_abrv ='" + prefixText.Trim() + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, sqlcnGPTERP);
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
string Primary_Key = "";
foreach (DataRow dr in dt.Rows)
{
Primary_Key = dr["branch_abrv"].ToString() + "{" + dr["Branch"].ToString() + "}";
i++;
}
return Primary_Key;
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.