本帖最后由 a1423213945 于 2010-02-10 19:11:22 编辑

解决方案 »

  1.   

    sf顶了.上个贴2.3分钟就结了.csdn.....good.大家解答啊.Thanks.
      

  2.   

            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>"); 
            }
      

  3.   

    ClientScript.RegisterStartupScript(this.GetType(), "PleaseCheck", "if(confirm('确定吗'))document.getElementById('textbox1').value='"+DateTime.Now.ToString("yyyy-MM-dd").Trim()+"';else 
    document.getElementById('textbox1').value='';",true);  
      

  4.   

    在后台生成 js里面的 confirm ,不管你怎么点,都会继续执行 下面的代码,明白?
      

  5.   

    前台:<%@ 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中做的选择向本页传参,然后后台代码根据参数调用函数。有高手的话,指教下,好学习啊!!!!
      

  6.   

    用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>
      

  7.   

    很显然,用OnClientClick是最方便的。
      

  8.   

    return confirm写在OnClientClick里就行了,如果写在后台文件点什么都会执行的