I am looking write a javascript method as such called when a dropdownlist changes value
function GetSt开发者_开发技巧uff(sender, destID){
var dest = document.getElementById(destID);
this.PageMethods.GetStuffs(sender, dest, null, null);
}
GetStuffs() is in the Codebehind as follows:
[WebMethod]
public static void GetStuffs(object sender, object dest)
{
DropDownList s = sender as DropDownList;
DropDownList d = dest as DropDownList;
d.Items.Add(new ListItem(s.SelectedValue));
}
I have a break point set at the method and alerts in the GetStuff() jscript method fire up until the PageMethod call, at which nothing happens. I have set OnSuccess and OnFailure methods up with alerts and they don't get fired.
Any thoughts? Am I doing something inherently wrong?
Couple of items to note:
- The GetStuffs class is returning void, so OnSuccess or OnFailure will not fire
- Even if you do return something back, the control on the UI will not update because the PageMethod just returns a value to the calling javascript but does not update the UI in anyway
- You will need to handle the OnSuccess event on the client & then update the dropdown on the client
- Any change to the control on the server does not reflect on the client using PageMethods
- The other point to note is that you are passing back an object of the dropdown which is a DOM element & casting it to a Server side control. This is not possible.
精彩评论