为什么带有自动回发功能的asp.net下拉菜单无法保留我选择的值 [英] Why asp.net dropdown with autopostback doesn't keep my selected value

查看:72
本文介绍了为什么带有自动回发功能的asp.net下拉菜单无法保留我选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如此处建议 ASP.NET Response.Redirect(请求.RawUrl)无效我确实将autopostback = true放在了下拉列表中以重新加载页面.

As advised here ASP.NET Response.Redirect(Request.RawUrl) doesn't work I did put autopostback = true on a dropdown list to reload my page.

但是在重新加载后,它也会将所选项目也重置为第一个项目.

But after reloading it resets also the selected item to first one.

然后在重新加载页面之前如何保持以前的值?我以为自动回传会完成这项工作吗?

How to keep my previous value before reloading the page then ? I thought autopostback would do that job ?

推荐答案

确保您没有在回发中重新填充下拉列表.

Make sure you're not repopulating the dropdown list on postback.

protected void Page_Load(object sender, EventArgs e)
{
    PopulateDropDownList();
}

将导致每次重置.而是尝试:

will cause it to be reset every time. Instead try:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        PopulateDropDownList();
    }
}

这篇关于为什么带有自动回发功能的asp.net下拉菜单无法保留我选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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