当前位置: 代码迷 >> ASP.NET >> 高分请问一个有关问题!
  详细解决方案

高分请问一个有关问题!

热度:4963   发布时间:2013-02-25 00:00:00.0
高分请教一个问题!!在线等。
我想实现的功能是
点击button
判断条件
if(条件正确)
{
  弹出来一个提示框,提示框有 确定和删除2个选项
  点击 确定
  {
  执行下面的代码
  }
  点击 取消
  {
  不执行
  }
}
我试了好多种方法都没解决,注意是要先判断在弹出框来,解决了就马上揭帖.

------解决方案--------------------------------------------------------
如果是WinForm就简单了。
C# code
private void button1_Click(object sender, EventArgs e)    {      bool condition = true;      // Check the condition here...      if(condition)      {        DialogResult dlg = MessageBox.Show("leoeofofofoog", "Test", MessageBoxButtons.OKCancel);        if(dlg == DialogResult.OK)        {          //Do something.        }        else        {          // Do nothing.        }      }    }
------解决方案--------------------------------------------------------
如果你的判断什么的是在服务器端完成的话,最好是用AJAX来完成了.

点击button回调进行判断.

再根据回调的结果弹出对话框
------解决方案--------------------------------------------------------
直接confirm
------解决方案--------------------------------------------------------
用js在客户端做验证???
JScript code
if (条件){    if(confirm('提示')){        form1.submit;//触发服务器事件        return true;    }    return false;//取消的话}
------解决方案--------------------------------------------------------
同意2楼的方法。或者在执行方法时用AJAX
------解决方案--------------------------------------------------------
WebForm也容易
C# code
private void button1_Click(object sender, EventArgs e){bool condition = true;if (condition){   if (confirm("确定吗?")){//Do something.}else{// Do nothing.}}}
------解决方案--------------------------------------------------------
-_-! 好快的楼啊
------解决方案--------------------------------------------------------
除了使用AJAX,很难做到这样,除非弹出层.
为了让问题简单而且合理的,应该是在一单击BUTTON时就询问.
------解决方案--------------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
{
if (1 == 1)
{
Response.Write("<script language=javascript>confirm('提示信息。');</script>");
if (true)
{
//执行这里语句
}
else 
{
//执行这里语句
}
}
}
------解决方案--------------------------------------------------------
使用层,里面做一个确定和取消两个按钮,你点击就弹出层,点击那个按钮就执行那个按钮的事件
------解决方案--------------------------------------------------------
if (条件){
if(confirm('提示')){
form1.submit;//触发服务器事件
return true;
}
return false;//取消的话
}
-------------
这个是可以的
------解决方案--------------------------------------------------------
LZ是在按鈕的屬性裡設置的Visible = "false"的吧,那在前端當然不能獲取到這個按鈕了.你只能使用js設置隱藏的按鈕button.style.visibility = 'hidden',這樣才能在前端獲取這個隱藏的按鈕

設計頁面aspx的代碼:
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hidden.aspx.cs" Inherits="Test_hidden" %><!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 type="text/javascript">    <!--        function CheckShow()    {        var condition = document.getElementById('<%=this.hdnCondition.ClientID %>').value;        var input = document.getElementById('<%=this.txtInput.ClientID %>').value;                if (input == condition)//判斷條件是否成立        {            if (window.confirm('Do you want to do?'))            {                document.getElementById('<%=this.btnHide.ClientID %>').click();//成立則觸發隱藏按鈕的click事件            }            else            {                //To Do something            }        }        else        {            event.returnValue = false;//條件不成立則甚麼都不做,也可以根據樓主的需要修改        }    }        function ShowMessage()    {        alert('I am run');    }        //-->    </script>    </head><body>    <form id="form1" runat="server">    <div>        <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>        <asp:Button ID="btnHide" runat="server" Text="Condition to Click" OnClientClick="ShowMessage()" />        <asp:Button ID="btnShow" runat="server" Text="Control to show" OnClientClick="CheckShow()" />                <input id="hdnCondition" runat="server" type="hidden" />    </div>    </form></body></html>
  相关解决方案