Web Asp.net 中的Messagebox 判断..

本文介绍如何在ASP.NET中利用MessageBox实现交互式确认对话框,包括客户端JavaScript代码示例及服务器端响应处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Web Asp.net 中的Messagebox 判断..

web 中使用messagebox 进行交互判断性程序执行, 没有在win form 中那么方便。

例:想到做下面的效果,在asp.net 中我们应该么这做。

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server"> &nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Save" runat="server" Text="Button" OnClientClick="return ConfirmSave();"/>

</form>

</body>

</html>

<script>

function ConfirmSave()

{

var x

x= document.getElementById('<%=TextBox1.ClientID%>').value

return confirm('确定要删除['+ x +' ]吗?');

}

</script>

特别要注意的是, 在显示messagebox 的时候显示提取 textbox1 中的内容时必须要document.getElementById('<%=TextBox1.ClientID%>').value 取客户端的值,如果直接取textbox1.text 取到的时空值,因为现在的内容还没有到server 端。

完整的例子:

前台Page:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server"> &nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Save" runat="server" Text="Button" OnClientClick="return ConfirmSave();"/>

</form>

</body>

</html>

<script>

function ConfirmSave()

{

var x

x= document.getElementById('<%=TextBox1.ClientID%>').value

return confirm('确定要删除['+ x +' ]吗?');

}

</script>

后台code:

Partial Class test

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click

Me.Response.Write("你点了确定保存,现在继续执行Click 里面的内容..")

End Sub

End Class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值