【发布时间】:2011-01-20 13:29:09
【问题描述】:
在我的 boxLang_OnSelectedIndexChanged() 事件中,我得到了这个:-
if (txtbox1.Text != "" && txtbox2.Text != "")
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.');", true);
txtbox1.Text = "";
txtbox2.Text = "";
}
现在正在发生的事情就是这样。当我从下拉列表中选择不同的项目时,此确认框会显示,但它首先清除文本框的内容,然后出现此确认框。我想要的是,只有在单击“确定”时才应清除文本框内容。
我做错了什么?请帮忙。谢谢。
编辑 @jgauffin ** 我在你有的地方输入了 return。现在发生的事情是它只是立即清除文本框......这次甚至没有显示确认框!现在怎么了??请回复..thnx**
编辑 2 我尝试如下:-
在我添加的 BindDropDown() 方法中:-
dropdownbox1.Attributes.Add("onChange","DisplayConfirmation()");
然后在我的 aspx 页面中,我添加了以下脚本,如下所示:-
<script type="css/javascript">
function DisplayConfirmation() {
if (confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.')) {
__doPostback('dropdownbox1','');
}
}
</script>
更改下拉列表的选定索引时不会调用此函数。怎么了?
编辑 3:- 好的,我将代码行更改如下:-
dropdownbox1.Attributes.Add("onchange", "javascript:return DisplayConfirmation()");
还是不行。我是 JavaScript 新手,所以遇到了问题。非常感谢您的帮助。
【问题讨论】:
-
输入错误的编辑器..已编辑它..对不起
标签: c# javascript asp.net