admin管理员组文章数量:1391951
I've got a dropdown list that is being populated via a webservice using ASP>NET AJAX. On the success callback of the method in javascript, I'm populating the dropdown via a loop:
function populateDropDown(dropdownId, list, enable, showCount) {
var dropdown = $get(dropdownId);
dropdown.options.length = 1;
for (var i = 0; i < list.length; i++) {
var opt = document.createElement("option");
if (showCount) {
opt.text = list[i].Name + ' (' + list[i].ChildCount + ')';
} else {
opt.text = list[i].Name;
}
opt.value = list[i].Name;
dropdown.options.add(opt);
}
dropdown.disabled = !enable;
}
However when I submit the form that this control is on, the control's list is always empty on postback. How do I get the populated lists data to persist over postback?
Edit: Maybe I'm ing at this backwards. A better question would probably be, how do I populate a dropdown list from a webservice without having to use an updatepanel due to the full page lifecycle it has to run through?
I've got a dropdown list that is being populated via a webservice using ASP>NET AJAX. On the success callback of the method in javascript, I'm populating the dropdown via a loop:
function populateDropDown(dropdownId, list, enable, showCount) {
var dropdown = $get(dropdownId);
dropdown.options.length = 1;
for (var i = 0; i < list.length; i++) {
var opt = document.createElement("option");
if (showCount) {
opt.text = list[i].Name + ' (' + list[i].ChildCount + ')';
} else {
opt.text = list[i].Name;
}
opt.value = list[i].Name;
dropdown.options.add(opt);
}
dropdown.disabled = !enable;
}
However when I submit the form that this control is on, the control's list is always empty on postback. How do I get the populated lists data to persist over postback?
Edit: Maybe I'm ing at this backwards. A better question would probably be, how do I populate a dropdown list from a webservice without having to use an updatepanel due to the full page lifecycle it has to run through?
Share Improve this question edited Sep 20, 2017 at 22:34 P.S. 16.4k14 gold badges65 silver badges86 bronze badges asked Oct 1, 2008 at 2:51 Glenn SlavenGlenn Slaven 34.2k27 gold badges117 silver badges166 bronze badges2 Answers
Reset to default 4You need to use Request.Form for this - you can't encrypt ViewState on the fly from the client - it would defeat the whole point of it :).
Edit: Responding to your Edit :) the Page Lifecycle is the thing that allows you to use the ViewState persistence in the first place. The control tree is handled there and, well, there's just no getting around it.
Request.Form is a perfectly viable way to do this - it will tell you the value of the selection. If you want to know all of the values, you could do some type of serialization to a hidden control.
Ugly, yes, But that's why god (some call him ScottGu) invented ASP.NET MVC :).
Although I'm not really sure how it does it the CascadingDropDown in the AJAX Control Toolkit does support this.
This is the line that appears to do it:
AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(this, 'set_ClientState', [ this._selectedValue+':::'+text ]);
But the simplest idea would be to put the selected value into a hidden input field for the postback event.
本文标签: netUpdate viewstate after populating a list with ASPNET AJAXStack Overflow
版权声明:本文标题:.net - Update viewstate after populating a list with ASP.NET AJAX - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744757221a2623535.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论