开发者

Passing page control from jscript to pagemethod in the codebehind?

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜