下拉列表未显示先前的值 [英] Dropdownlist not showing previous value

查看:68
本文介绍了下拉列表未显示先前的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个带有autopostback false的asp.net下拉列表.

我编写了js代码,以在下拉列表值更改时显示确认消息.

Hi all,

I have an asp.net dropdownlist with autopostback false.

I have written js code to display confirm message while dropdown value changed.

function ConfirmAbsent(ddlPresence) {
            if (ddlPresence != null) {
                var myValue = ddlPresence.options[ddlPresence.selectedIndex].text;
                var blnAbsent = confirm("This will mark as "+ myValue +". Please confirm clicking OK.");

                if (blnAbsent) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }



并将此属性添加到下拉列表中,如下所示



And add this attribute to dropdownlist like below

ddlUserPresence.Attributes.Add("onchange", "if (!ConfirmAbsent(" + ddlUserPresence.ClientID
                        + ")) return; else __doPostBack('"
                        + ddlUserPresence.UniqueID + "', '');");



当我单击确定"时,它回发页面正常工作,但是当我单击取消"按钮时,它没有显示我以前的值,而是显示了当前值.

因此,当我单击取消"按钮时,它应该向我显示以前的值.请提供帮助.
我也尝试过隐藏字段.但仍然无法正常工作.



When i click on ok it postback the page working correctly, but when i click on cancel button it is not showing me the previous value instead showing the current value.

So when i click on cancel button it should show me the previous value.Please help.
I have tried hidden field also.But still its not working.

推荐答案

如果您只想使用javascript在客户端执行此操作,则必须在javascript中创建一个临时占位符变量以保存当前值.页面加载后,将此值设置为下拉列表的初始值.当某人单击确认时的取消"时,您只需要将下拉列表的选定值重置为临时占位符值即可.当用户接受确认时,您只需要将占位符更新为新值即可.
If you wish to do this solely on the client side with javascript, you''ll have to create a temporary placeholder variable in the javascript to hold the current value. When the page loads, set this value to the initial value of the dropdownlist. When someone clicks Cancel on the confirmation, you just have to reset the selected value of the dropdownlist to the temporary placeholder value. When a user accepts confirmation, you just have to update the placeholder to the new value.


这篇关于下拉列表未显示先前的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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