asp.net 很简单的ConfirmBox 对话框 实现

 

    最近有一个需求要实现ConfirmBox的效果,由于时间关系不想用Ajex技术(觉得实现起来很麻烦),后来想了一个变通的方法. 

    虽然会实现,但是效果是有了,user才不管会不会刷新呢,看起来是那回事,而且做的快就行了.

    有时候先进的技术不一定就能达到很好的效果,做什么程序都要看user的要求呀!

实现如下

1.放一个能临时存放值的东西(要隐藏哟),我放的TextBox

 <input   type="hidden"   runat="server"   id="lblView">

2.写js判断user的选择

function ConfirmBox()
  {
    if(window.confirm("test"))
    {
        window.document.getElementById("txtView").innerText = 'test';
    }
  }

3.把confirmBox()事件放到某个按钮上(cs中写)

this.Button2.Attributes.Add("onclick", "javascrpt:ConfirmBox();");

4.在那个按钮的点击事件中(服务器端)判断那个隐藏的控件的值是否改变.

protected void Button2_Click1(object sender, EventArgs e)
    {
        if (this.lblView.Text == "test")
        {
            this.txtView.Text = "haha";
        }
    }

posted on 2007-10-19 10:11  LongSky  阅读(162)  评论(0编辑  收藏  举报

导航