无法将字符串数组分配给asp:HiddenField

Cannot assign string array to an asp:HiddenField

本文关键字:asp HiddenField 分配 数组 字符串      更新时间:2023-09-26

我试图将数组(globalaProviders)内容分配给asp隐藏字段(aProvidersHdn),并在单击WebLinkButton(自定义控件)后在服务器中获取值。

在下面的Javascript代码中,我可以将JSON文件中的字符串值分配给globalaProviders数组。当我试图将数组中的值分配给隐藏字段(aProvidersHdn)时,我会在客户端和服务器中获得一个空值。

这是JavaScript代码:

<script language="javascript" type="text/javascript">function bbPlusPullTest()
{
globalaProviders=[];
aProvidersHdn="";
$.each(providers, function(i,v){
globalaProviders[i,0]=v.uri;
     globalaProviders[i,1]=v.name;
     globalaProviders[i,2]=v.description;
});
$("#<%=aProvidersHdn.ClientID%>").val(globalaProviders);
alert("aProvidersHdn = "+ aProvidersHdn); 
//empty value obtained
}
</script>
//I’ve added this to trigger a postback after the WebLinkButton(custom control) is clicked so the values of the hidden field can be send to the server.
<% if (!Page.IsPostBack) { %>
<script type="text/javascript">
window.onload = function() {
   __doPostBack("<%= MedicalHistory.ClientID %>", "");
}
</script>

以下是隐藏字段的分配:ASPX

<asp:HiddenField ID="aProvidersHdn" runat="server" /> 
//Custom Control Does not has a Click event
<cc1:WebLinkButtonControl ID="MedicalHistory" Key="viewccd" PostBackUrl="BBPlusPullTest.aspx" CssClass="panelitem" runat="server"></cc1:WebLinkButtonControl>

这是SERVER 中的代码

if (!IsPostBack)
{
MedicalHistory.Attributes.Add("onclick", "bbPlusPullTest(); return false;");
}
else
{
string providersArray = aProviders.Value;
}

这是供应商的代码:

providers = function(registries, callback){
    var requests = [];
    jQuery.each(registries, function(i, r){
      requests.push(jQuery.ajax({
        type: "GET",
        url: r+"prov.json"
      }));
    });
    var providers = [];
    jQuery.when.apply(null, requests).then(function(){
      jQuery.each(arguments, function(responseNum, arg){
        if (responseNum>=requests.length) {
          return;
        }
        jQuery.each(arg, function(i, provider){
          providers.push(provider);
        });
      });
      callback(providers);
    });

我做错了什么?

只需使用一些分隔符连接数组中的字符串然后在服务器端上用这个分隔符分割结果字符串