ASP.NET AJAX延迟


                    

我正在使用VS2010,C#开发我的ASP.NET Web应用程序。 我有一个用于选择省的组合框和另一个用于选择城市的组合框,当用户选择一个省时,城市组合框应立即显示属于该省的城市。
我已经在页面中插入了一个AJAX脚本管理器,也在其中插入了组合框的还有一个AJAX更新面板(均来自工具箱)。 然后,我启用了省份组合框自动回发属性,以便当用户更改其选择时,我可以检测到它并相应地更改城市组合框的内容。
当我在页面启动时将数据库中的省名和城市名加载到列表中时,它工作正常(当然,此加载过程在if(!IsPostback)语句中执行,因此数据仅加载一次)。 我认为更新城市组合框所需的时间比所需时间多一点,因为当用户更改省份组合框选择时会有回发,执行此操作的最佳(正确)方法是什么? 可以吗 有更好的方法吗? 更改省份组合框后,由于目前延迟很短,我如何立即更新城市组合框。</ p>

谢谢</ p>
     </ div>

展开原文

原文

I'm using VS2010,C# to develop my ASP.NET web app. I have some a combo box for selecting province and another combo box for selecting cities, when user selected a province, the city combo box should immediately display cities belonging to that province. I have inserted an AJAX script manager into my page, also an AJAX update panel (both from toolbox) in which I've inserted my combo boxes. Then I enabled province combo box autopostback property so that when user changes his selection, I can detect it and change contents of city combo box accordingly. It works fine, as I load province and city names from my database into a list at page startup (of course this load process is performed in a if(!IsPostback) statement so that data is loaded only once). I think the time needed to update city combo box is a bit more than what is required, as there is a postback when user changes province combo box selection, what is the best (and correct) way of performing this operation? is it ok? are there any better ways of doing it? how can I IMMEDIATELY update city combo box after province combo box selection is changed, as currently there is a short delay.

thanks

1个回答


如果在服务器端使用ASP.NET回发,总是会出现延迟。</ p>

另一种选择是在初始加载时向您的页面输出一些JSON,其中包含您所有省份的数组,每个省份的嵌套数组包含其各自的城市。</ p>

然后,您可以删除自动回发并使用JavaScript在客户端进行所有操作。 每当选定的省份发生变化时,您只需要解析JSON并将所有关联的城市添加到第二个下拉列表中即可。</ p>
     </ div>

展开原文

原文

You're always going to have a delay if you do it on the server side with an ASP.NET postback.

Another option would be to output some JSON to your page on initial load which contains an array of all your provinces with a nested array for each province containing its respective cities.

Then you can remove the auto postback and do everything client side with JavaScript. Whenever the selected province changes you just need to parse your JSON and add all the associated cities to the second dropdown list.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐