我在服務器端有一個填充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 –