function webMethodCaller( ids){
PageMethods.FormatName(ids,
onFormatNameSuccess,
onFormatNameFail,
onFormatNameTimeout);
result=document.getElementById("HiddenField1").value;
// i want to do something else based on result after this
}
function onFormatNameSuccess(response)
{
debugger;
var res="";
for(var i=0,il=response.length; i<il;i++){
res+=response[i];
}
document.getElementById("HiddenField1").value = res;
}
function onFormatNameFail (exception, ctx, methodName)
{
alert("Method:"+ methodName +"\n"+
exception.get_exceptionType() +"\n"+
exception._message);
}
function onFormatNameTimeout ()
{
alert("Timeout");
}
///////////////////////////////////////////////
<form id="form1" runat="server">
<asp:HiddenField ID="hdnReturnValue" runat="server" Value="xx" />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input type="hidden" id="hiddnvalue" runat="server" value="" />
<asp:ScriptManager ID="yourScriptManager" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
</form>
the web method is the folloiwng
///////////////////////////////////////
[WebMethod, ScriptMethod]
static public List<String> FormatName(string featureIds)
{
string[] rawdata = featureIds.Split(new char[] { ',' });
List<String> strings = new List<String>();
for (int i = 0; i < rawdata.Length; i++)
{
strings.Add(rawdata[i]);
}
// strings.Add(FirstName);
// strings.Add(LastName);*/
//Session["result"] = strings;
// hdnReturnValue.value = strings;
// HiddenField1.Value = featureIds;
// hiddnvalue.Value = featureIds;
return strings;
// LastName + ", " + FirstName;
}
|