`
wsql
  • 浏览: 11791733 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

Web Asp.net 中的Messagebox 判断..

阅读更多

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics