在下拉框中的选择的指数的变化激发事件背后实施code JavaScript的确认框 [英] Implementing javascript confirm box in code behind on drop down box's selected index change event firing

查看:182
本文介绍了在下拉框中的选择的指数的变化激发事件背后实施code JavaScript的确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的boxLang_OnSelectedIndexChanged()事件,我得到这个: -

 如果(txtbox1.Text =!&放大器;&安培;!txtbox2.Text =)
        {
            ScriptManager.RegisterStartupScript(页,Page.GetType(),确认,确认(更改语言将清除文本框文本单击OK继续。');,真正的);
            txtbox1.Text =;
            txtbox2.Text =;
        }

现在正在发生的事情是。当我从下​​拉列表中选择一个不同的项目这个确认框不会出现,但它首先清除文本框的内容,然后出现此确认框。我要的是点击OK时,文本框的内容应该只清除。

我是什么做错了吗?请help.Thanks。

编辑
@jgauffin
**我打回,你有。现在正在发生的事情是,它只是清除文本框右侧away..didn't甚至显示的确认框这一次!什么是错?现在请reply..thnx **

修改2
我试过如下: -

在我的BindDropDown()方法,我又说: -

  dropdownbox1.Attributes.Add(的onChange,DisplayConfirmation());

然后在我的aspx页面我已经添加下面的脚本如下: -

 <脚本类型=的CSS / JavaScript的>
功能DisplayConfirmation(){
  如果(确认(更改语言将清除文本框中的文本。单击OK继续。')){
    __doPostBack('dropdownbox1','');
  }
}< / SCRIPT>

在下拉选择的指标发生变化,该​​功能是没有得到调用。怎么了?

修改3: -
好吧,我改变code线如下: -

  dropdownbox1.Attributes.Add(的onchange,JavaScript的:返回DisplayConfirmation());

仍然不会工作。我是新来的JavaScript和都这么有问题。帮助将非常AP preciated。


解决方案

  ScriptManager.RegisterStartupScript(页,Page.GetType(),确认,返回确认('更改语言,将清除文本框文本单击OK继续');,真);

收益需要打破取消该过程。

Inside my boxLang_OnSelectedIndexChanged() event I got this :-

 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 = "";
        }

Now what is happening is that. When I select a different item from the drop down list this confirm box does show up BUT it first clears the content of the text boxes and then this confirm box appears. What I want is that the textboxes content should be cleared ONLY when OK is clicked.

What am I doing wrong? Please help.Thanks.

edit @jgauffin ** I typed return where you have. Now what is happening is that its just clearing the textboxes right away..didn't even show the confirm box this time! Whats wrong now?? Please reply..thnx**

edit 2 I tried as follows:-

Inside my BindDropDown() method I added :-

dropdownbox1.Attributes.Add("onChange","DisplayConfirmation()");

then in my aspx page I have added the following script as follows:-

<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>

This function is not getting called when drop down's selected index is changed. What's wrong?

edit 3:- ok I changed the line of code as follows:-

 dropdownbox1.Attributes.Add("onchange", "javascript:return DisplayConfirmation()");

Still wont work. I am new to JavaScript and all so having problems. Help will be much appreciated.

解决方案

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "return confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.');", true);

return is needed to break the process on cancel.

这篇关于在下拉框中的选择的指数的变化激发事件背后实施code JavaScript的确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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