我在服务器端有一个填充dropdownlist
的函数。我打电话跟客户端的按钮,这个功能在Javascript与PageMethods
点击这样的:如何在ASP.net中用Javascript调用带客户端副作用的C#服务器端函数
<asp:ScriptManager ID="smMain" runat="server" EnablePageMethods="true" />
<asp:Button runat="server" ID="SearchButton" Text="Search" OnClientClick="SearchButtonClick();return false;"/>
<asp:DropDownList runat="server" ID="SearchCityDropDownList" Width="100px"/>
而且
function SearchButtonClick() {
PageMethods.SearchSearchButtonActivity(onSucess, onError);
}
function onSucess(result) {
alert(result);
}
function onError(result) {
alert('Cannot process your request at the moment, please try later.');
}
服务器端功能:
[WebMethod]
public static string SearchButtonActivity()
{
string result = "Everything is OK!";
foreach (string value in getCityList())
{
SearchCityDropDownList.Items.Add(new ListItem(value));
}
return result;
}
当运行这段代码,然后点击按钮只显示"Everything is OK!"
提醒和
dropdownlist仍为空。
所以请帮助我解决这个问题,我认为这是后背部有问题的,因为当我调试代码,items of dropdownlist are full but don't show that.
谢谢
所以你越来越“一切都好!”作为回应,但下拉仍然是空的,是吗? –
你在哪里绑定了'dropdownlist'? – BNN
是@HarveySpecter –