Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
回发时不会保留使用JavaScript的值集_Javascript_Asp.net_Postback - Fatal编程技术网

回发时不会保留使用JavaScript的值集

回发时不会保留使用JavaScript的值集,javascript,asp.net,postback,Javascript,Asp.net,Postback,我的asp.net页面中有两个列表控件,正在使用javascript填充第二个列表控件。问题是脚本执行时,我可以看到值从第一个列表框(ConfiguredOrgListBox)移动到第二个列表框(SelectedOrgListBox),但当我尝试使用submit按钮保存时,我发现第二个列表为空,第一个列表框与之前一样。下面是脚本和标记 //call this method to register the script private void CreateMoveOrga

我的asp.net页面中有两个列表控件,正在使用javascript填充第二个列表控件。问题是脚本执行时,我可以看到值从第一个列表框(ConfiguredOrgListBox)移动到第二个列表框(SelectedOrgListBox),但当我尝试使用submit按钮保存时,我发现第二个列表为空,第一个列表框与之前一样。下面是脚本和标记

    //call this method to register the script    
    private void CreateMoveOrganizationScript(StringBuilder sb) {
        sb.Append( @"<script language=javascript type=text/javascript>;
                    function moveOrganisation() {");            
        sb.Append( @"var source = document.getElementById('"+ ConfiguredOrgListBox.ClientID  +@"');
                    var target = document.getElementById('"+SelectedOrgListBox.ClientID+ @"');
                    if ((source != null) && (target != null)) {
                    var newOption = new Option();
                    newOption.text = source.options[source.options.selectedIndex].text;
                    newOption.value = source.options[source.options.selectedIndex].value;

                    target.options[target.length] = newOption;
                    source.remove(source.options.selectedIndex)  ;
                    }            
                } </script>");            
    }
//调用此方法以注册脚本
私有void CreateMoveOrganizationScript(StringBuilder sb){
某人附加(@);
函数移动(){”);
sb.Append(@“var source=document.getElementById(“+ConfiguredOrgListBox.ClientID+@”);
var target=document.getElementById(“+SelectedOrgListBox.ClientID+@”);
如果((源!=null)和&(目标!=null)){
var newOption=newOption();
newOption.text=source.options[source.options.selectedIndex].text;
newOption.value=source.options[source.options.selectedIndex].value;
target.options[target.length]=newOption;
source.remove(source.options.selectedIndex);
}            
} ");            
}
加价

      <asp:Label ID="ConfiguredOrgLabel" runat="server" Text="Available Organizations"></asp:Label><br />
      <asp:ListBox ID="ConfiguredOrgListBox" runat="server" Width="98%" Height="100px"></asp:ListBox>
       <input id="MoveOrgRight" type="button" value=">>" onclick="moveOrganisation()" />
      <asp:Label ID="SelectedOrgLabel" runat="server" Text="Selected VNA Organizations"></asp:Label><br />
      <asp:ListBox ID="SelectedOrgListBox" runat="server" Width="98%" Height="100px"></asp:ListBox>


请让我知道我做错了什么

问候,,
JeeZ

您需要在回发期间处理这些更改。当回发发生时,ASP.NET引擎从视图状态加载控件的数据,并且它不知道客户端使用javascript修改了值,因此您应该手动从请求中提取这些值。

根据,这是因为列表框不会回发来告诉后端它已更改。他们使用一个隐藏字段,该字段保存有关JavaScript所做更改的信息,然后在回发时更新后端。

感谢Andrew&Drackir,我是java脚本asn asp.net的新手,因此不知道这个概念。我有一个问题列表控件和隐藏字段都是网络控件,如果我们可以设置隐藏控件的值,我们应该能够将列表控件的值设置得太正确(它们的行为方式应该相同!!)。。。Drackir我尝试了链接中的建议,但有些甚至不起作用,当我调试时,我发现隐藏字段正在初始化,但在服务器端,隐藏字段的值为空!!:(控件是否与“提交”按钮的
完全相同?是的,它们的格式相同,但分区不同,我想这不应该是个问题。我不认为表单字段(隐藏或其他)是否已禁用?我发现了一个与文本字段被禁用和忽略有类似问题的问题。感谢您的回答并帮助我解决此问题…这些问题和回答帮助我更好地理解了这些概念…我编写了一个小asp.net程序,在该程序中,我使用java脚本在html按钮上填充了一个文本框,然后单击并显示提交按钮点击时填充的值…程序在隐藏字段的任何帮助下运行我想知道列表我们需要隐藏字段还是控件可以在没有隐藏字段的情况下保持更改..将调查并发布结果..再次感谢您的时间我很感激:)