UserControl上的下拉列表在每次回发时都会刷新 [英] Dropdownlist on UserControl is refreshing on each postback

查看:73
本文介绍了UserControl上的下拉列表在每次回发时都会刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我开发了一个包含多个页面和用户控件的Web应用程序。但是,我在其中一个用户控件上遇到问题。



背景:



用户控件有多个文本框,标签和下拉列表。有四个下拉列表,彼此依赖。他们是国家,州,地区和城市。选择国家/地区,填写状态,选择状态,区域填写等等。



下拉菜单将autopostback设置为true。



此用户控件在永久地址和通讯地址的同一页面上使用TWICE。



问题:



如果在其中一个用户控件实例中更改了国家/地区,则其他用户控件上的选择将重置为selectedIndex 0.



我尝试使用Enableviewstate,但没有用。



请求:



非常感谢任何快速指导。

Hi,

I have developed a web application with multiple pages and user controls. However, I am facing an issue on one of the user controls.

The Background:

The User Control has multiple textboxes, lables and dropdowns. there are four dropdowns, which are dependent on one another. They are Country, State, District and City. On country is selected, state gets filled and on State is selected, district gets filled and so on.

the dropdowns have autopostback set to true.

This User control is used TWICE on the same page for Permanent Address and communication Address.

The Problem:

If the country is changed in one of the instances of the user control, the selection on other usercontrol is reset to selectedIndex 0.

I tried with Enableviewstate, but of no use.

Request:

Any quick guidance on this is highly appreciated.

推荐答案

你把这个用过的控制代码放在哪里绑定?是在页面加载检查它将放在里面!ispostback



格式正确



if(!ispostback

{

你的代码...

}
where are u placed this used control code to bind ? is it in pageload check for it will placed inside !ispostback

correct format

if(!ispostback
{
your code...
}


感谢大家花时间和试图帮助我。



最初我认为这可能是Usercontrol和DropDownList的问题。



然而,经过深度锻炼后,我可以成功控制DropDownList。



错误发生在:



编码人员使用Property为DropdownList分配值并检索值。



虽然检索部分工作正常,但是分配部分正在搞砸这个过程。我改变了它,现在工作正常。





有问题的物业代码:

Thanks to all for taking your time and trying to help me.

Initially I thought it might be the issue of Usercontrol and DropDownList.

However, after deeper exercise, I could succeed in getting control of the DropDownList.

The Error was in:

The coders had used Property for assigning value to DropdownList and to retrieve value.

Though the retrieval part was working fine, the assigning part was screwing the process. I changed it and now it is working fine.


The Property code where issue was there:
public string GetStateID
       {
           get
           {
               return cmbState.SelectedItem.Value.ToString();
           }
           set
           {
               cmbState.SelectedItem.Value = value;
           }
       }





我评论了集{}部分,并使用单独的函数为值赋值DropdownList。



现在工作正常。





感谢所有的建议和指导。



问候



I have commented the set{} Part and used separate function to assign value to the DropdownList.

Now it is working fine.


Thanks to all for the suggestions and guidance.

Regards


这篇关于UserControl上的下拉列表在每次回发时都会刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆