function webMethodCaller( ids){
PageMethods.FormatName(ids, onFormatNameSuccess, onFormatNameFail, onFormatNameTimeout);
// i want to do something else based on result after this
//if I try to get the value in a hidden filed in here it is empty
}
function onFormatNameSuccess(response)
{
var res="";
for(var i=0,il=response.length; i<il;i++){
res+=response[i];
}
// i am trying to store the value in a hidden field for later use
document.getElementById("HiddenField1").value = res;
//if i try to see the vaue of the hidden fiedl in here it is there but not ouside this fucntion
}
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;
}
|