裏面我boxLang_OnSelectedIndexChanged()事件中執行代碼的JavaScript確認框的背後我得到這個: -在下拉框中的選擇指數變化事件觸發
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 **我輸入回報,你有。現在發生的事情是,它只是馬上清除文本框,這次甚至不顯示確認框!現在怎麼了?請reply..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>
此函數沒有被調用whe n下拉選擇的索引被更改。怎麼了?
編輯3: - 好,我改變了一行代碼,如下所示: -
dropdownbox1.Attributes.Add("onchange", "javascript:return DisplayConfirmation()");
仍然不會工作。我是JavaScript新手,並且都遇到了問題。幫助將不勝感激。
類型化編輯器通過mistake..have editted it..sorry – Serenity 2011-01-20 13:34:07