弹对话框! 本帖最后由 a1423213945 于 2010-02-10 19:11:22 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sf顶了.上个贴2.3分钟就结了.csdn.....good.大家解答啊.Thanks. protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "11") ClientScript.RegisterStartupScript(this.GetType(), "", " <script>if(confirm('确定显示时间!'))document.getElementById(\"TextBox1\").value=\""+ DateTime.Now.ToShortDateString().ToString().Trim() +"\"; </script>"); } ClientScript.RegisterStartupScript(this.GetType(), "PleaseCheck", "if(confirm('确定吗'))document.getElementById('textbox1').value='"+DateTime.Now.ToString("yyyy-MM-dd").Trim()+"';else document.getElementById('textbox1').value='';",true); 在后台生成 js里面的 confirm ,不管你怎么点,都会继续执行 下面的代码,明白? 前台:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %><!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></title></head><body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form></body></html>后台:using System;public partial class Default8 : System.Web.UI.Page{ string flag; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["flag"] != null) { flag = Request.QueryString["flag"].ToString(); if (flag == "true") { Bind(); } } } } protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "11") { ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>if (confirm('确定显示时间?')) {location.href='Default8.aspx?flag=true'} else {location.href='Default8.aspx?flag=false'}</script>"); } } private void Bind() { TextBox1.Text = DateTime.Now.ToShortDateString(); }}我也是新手,帮你想了一会,水平有限,实在没想出好的办法来,用了这个我自己觉得挺怪异的方法。根据confirm中做的选择向本页传参,然后后台代码根据参数调用函数。有高手的话,指教下,好学习啊!!!! 用js写吧<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %><!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>无标题页</title> <script language="javascript"> function check() { var now=new Date(); var year=now.getYear(); var month=now.getMonth(); var day=now.getDate(); var hours=now.getHours(); var minutes=now.getMinutes(); var seconds=now.getSeconds(); var CurrentTime=year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds; if(document.getElementById("TextBox1").value=="11") { if(confirm("确定吗")) { document.getElementById("TextBox1").value=CurrentTime; } else { document.getElementById("TextBox1").value=""; } } } </script></head><body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="check();" /> </form></body></html> 很显然,用OnClientClick是最方便的。 return confirm写在OnClientClick里就行了,如果写在后台文件点什么都会执行的 解决下下拉菜单没效果,别人能用我不能用。。。 遇到神问题 数据库被注入 创建文件夹的疑问? ASP.NET看来真害了不少人 ListView 绑定ImageList 的 问题...... web程序如何获得局域网中所有可用的打印机名字? 如何把一个arraylist绑定到一个datagrid上,并设成超连接? 如何实现单点登录 谁能说说出错的原因可能是什么?内详 版主留情!!!:) gridview 从数据库获取外部链接,怎么识别超链接 只用一个母版页…怎样实现多个页面重用…
{
if (TextBox1.Text == "11")
ClientScript.RegisterStartupScript(this.GetType(), "", " <script>if(confirm('确定显示时间!'))document.getElementById(\"TextBox1\").value=\""+ DateTime.Now.ToShortDateString().ToString().Trim() +"\"; </script>");
}
document.getElementById('textbox1').value='';",true);
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>后台:using System;public partial class Default8 : System.Web.UI.Page
{
string flag;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["flag"] != null)
{
flag = Request.QueryString["flag"].ToString();
if (flag == "true")
{
Bind();
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "11")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>if (confirm('确定显示时间?')) {location.href='Default8.aspx?flag=true'} else {location.href='Default8.aspx?flag=false'}</script>");
}
} private void Bind()
{
TextBox1.Text = DateTime.Now.ToShortDateString();
}
}我也是新手,帮你想了一会,水平有限,实在没想出好的办法来,用了这个我自己觉得挺怪异的方法。根据confirm中做的选择向本页传参,然后后台代码根据参数调用函数。有高手的话,指教下,好学习啊!!!!
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %><!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>无标题页</title>
<script language="javascript">
function check()
{
var now=new Date(); var year=now.getYear(); var month=now.getMonth(); var day=now.getDate(); var hours=now.getHours(); var minutes=now.getMinutes(); var seconds=now.getSeconds(); var CurrentTime=year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
if(document.getElementById("TextBox1").value=="11")
{
if(confirm("确定吗"))
{
document.getElementById("TextBox1").value=CurrentTime;
}
else
{
document.getElementById("TextBox1").value="";
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="check();" />
</form>
</body>
</html>