1

我需要显示确认框“您确定要继续吗?” 如果“是”,我需要清除 ASP.NET 文本框值。否则不应清除。

4

5 回答 5

1

在您的 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()'/>
于 2010-02-08T09:25:36.050 回答
1
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();"

希望这可以帮助

于 2010-02-08T09:26:01.820 回答
1

如果您下载AjaxControlToolkit,您可以使用 ConfirmButtonExtender 在单击按钮以继续操作或取消后向用户显示一个简单的确认框

您可以在此处查看示例,在此处查看有关如何实现此功能的教程

好的,我刚刚注意到有关单选按钮的一些信息,无论如何,如果您想在 .Net 项目中实现 JavaScript 解决方案,AjaxControlToolkit 是一个不错的起点

于 2010-02-08T09:38:34.263 回答
0

如果这是您的文本框标记:

<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>
于 2010-02-08T09:41:41.510 回答
0
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");
}

该功能中还有一个计时器停止。如果按“确定”计时器停止确认框,并且它也重定向到新页面“Default2.aspx”

否则,如果选择取消,则不会发生任何事情。

于 2011-07-14T09:02:56.843 回答