문제

확인란을 보여 주어야합니다. "계속하고 싶습니까?" "예"인 경우 ASP.NET TextBox 값을 지울 필요가 있습니다. 그렇지 않으면 지우지 않아야합니다.

도움이 되었습니까?

해결책

function doConfirm(){
  if (confirm("Are you sure you want to continue?")){
     var mytxtbox = document.getElementById('<% =myAspTextBox.ClientID %>');
     mytxtbox.value = '';
  }    

}

참고 myasptextbox는 ASP의 이름을 말합니다 : TextBox Controls ID 속성

<asp:textbox ID="myAspTextBox" runat="server" OnClientClick="javascript:doConfirm();"

도움이 되었기를 바랍니다

다른 팁

ASP 텍스트 상자 태그에 다음을 추가하십시오.

OnClientClick="javascript:testDeleteValue();"

... 그리고이 스크립트를 추가하십시오.

<script>
function testDeleteValue()
{
   if (window.confirm('Are you sure You Want To continue?'))
      document.getElementById("<%=<th id of your textbox>.ClientID%>").value = '';
}  
</script>

라디오 박스를 클릭 할 때 이런 일이 발생하려면이 태그에 넣고 OnClientClick을 OnClick으로 교체하십시오.

<input type='radio' onclick='testDeleteValue()'/>

다운로드하면 ajaxcontroltoolkit voluctbuttonextender를 사용하여 버튼을 클릭 한 후 조치 또는 취소 후 간단한 확인 상자를 사용자에게 표시 할 수 있습니다.

너는 볼 수있어 여기 예를 들어 여기 이 구현 방법에 대한 자습서

좋아, 방금 라디오 버튼에 대한 비트를 발견했습니다. 어쨌든 AjaxControlToolkit은 .NET 프로젝트에서 JavaScript 솔루션을 구현하려면 시작하기에 좋은 장소입니다.

이것이 텍스트 상자 마크 업이면 :

<asp:textbox id="txtInput" runat="server" />

그리고 이것은 확인을 트리거하는 버튼입니다.

<asp:button id="btnSumbit" runat="server" onclientclick="return clearOnConfirm();" text="Submit" />

그런 다음 다음 JavaScript가 필요합니다.

<script type="text/javascript">
function clearOnConfirm() {
    if (confirm("Are you sure you want to continue?")) {
        document.getElementById("<%=txtInput.ClientID %>").value = '';
        return true;
    } else {
        return false;
    }
}
</script>

당신이 원하는 것은 텍스트 상자를 지우는 것만이지만 항상 Postback을 계속 사용하면 위와 같이 False를 반환 할 필요는 없지만 항상 아래와 같이 True를 반환 할 필요가 없습니다. 이 시나리오에서는 사용자에게 표시하는 메시지를 다시 생각해야합니다.

<script type="text/javascript">
function clearOnConfirm() {
    if (confirm("Are you sure you want to continue?")) {
        document.getElementById("<%=txtInput.ClientID %>").value = '';
    } 
    return true;
}
</script>
function stopTimer() {        
if (window.confirm('Are you sure You Want To continue?')) {
$find('Timer1')._stopTimer()
return true;
}
else {
return false;
}

<asp:Button ID="Btn_Finish" runat="server" Text="Finish" Width="113px" OnClick="Btn_Finish_Click" OnClientClick="return stopTimer();" Height="35px" 

protected void Btn_Finish_Click(object sender, EventArgs e)
{
Timer1.Enabled = false;
// if any functions to be done eg: function1();
Response.Redirect("~/Default2.aspx");
}

함수에는 타이머 중지도 있습니다. "OK"타이머를 누르면 확인란이 중지되고 새 페이지 "default2.aspx"로 리디렉션됩니다.

다른 사람이 취소하면 아무 일도 일어나지 않습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top