「続行しますか?」という確認ボックスを表示する必要があります。「はい」の場合、ASP.NET テキストボックスの値をクリアする必要があります。それ以外の場合は、クリアしないでください。
5 に答える
AjaxControlToolkitをダウンロードすると、ConfirmButtonExtenderを使用して、ボタンをクリックしてアクションを続行するかキャンセルした後に、簡単な確認ボックスをユーザーに表示できます。
例についてはこちらを、これを実装する方法のチュートリアルについてはこちらをご覧ください。
さて、ラジオ ボタンについて少し気付きました。いずれにせよ、.Net プロジェクトに JavaScript ソリューションを実装したい場合は、AjaxControlToolkit から始めるのが良いでしょう。
あなたの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()'/>
function doConfirm(){
if (confirm("Are you sure you want to continue?")){
var mytxtbox = document.getElementById('<% =myAspTextBox.ClientID %>');
mytxtbox.value = '';
}
}
myAspTextBox は、asp:textbox コントロールの ID プロパティの名前を参照することに注意してください。
<asp:textbox ID="myAspTextBox" runat="server" OnClientClick="javascript:doConfirm();"
お役に立てれば
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」にリダイレクトされます
それ以外の場合は、キャンセルを選択すると何も起こりません。
これがテキストボックスのマークアップの場合:
<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>
テキストボックスをクリアするだけで、常にポストバックを続行する場合は、上記のように 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>