2013-11-21 29 views
0

我想在text_changed事件上有一個確認消息並在ok上執行不同的代碼集並取消。幫我看看這些代碼在代碼後面執行不同的代碼在確認好並取消

<script type = "text/javascript"> 
    function Confirm() { 
     var confirm_value = document.createElement("INPUT"); 
     confirm_value.type = "hidden"; 
     confirm_value.name = "confirm_value"; 
     if (confirm("Do you want to save data?")) { 
      confirm_value.value = "Yes"; 
     } else { 
      confirm_value.value = "No"; 
     } 
     document.forms[0].appendChild(confirm_value); 
    } 
    </script> 

<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox> 

代碼隱藏

protected void TextBox1_TextChanged(object sender, EventArgs e) 
    { 
     // TextBox1.Attributes.Add("OnClientClick", "Confirm()"); 
     string confirmValue = Request.Form["confirm_value"]; 
     if (confirmValue == "Yes") 
     { 
      //Your logic for OK button 
     } 
     else 
     { 
      //Your logic for cancel button 
     } 
    } 
public void OnConfirm(object sender, EventArgs e) 
    { 
    } 

都成了這個樣子,但我想這樣做,而無需使用按鈕,我想使用文本框只

+0

你在哪裏打電話給你的JS功能? – geedubb

+0

請參閱相關修改 –

+0

@geedubb請幫助我 –

回答

0

你可以從以下鏈接找到答案。

https://stackoverflow.com/a/20117247/1381667

看來你張貼同樣的問題2倍,這是完全確定,但嘗試,如果你認爲這是不是表示你的問題很好,而不是發佈新的編輯您的問題。