asp.net中的Confirm

今天遇到个棘手的问题,就是在asp.net中使用confirm来处理,不是单纯的用Button1.Attributes.Add("onclick", "javascript:renturn confirm('测试')");的

网上查了之后的解决办法一是:


ContractedBlock.gif ExpandedBlockStart.gif aspx中主要代码
<body>
    
<form id="form1" runat="server">    
    
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        Text
="无confirm" />
    
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="赋值" />
    
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
</form>
</body

还有aspx.cs页面
 protected void Page_Load(object sender, EventArgs e)
    {

    }
    
protected void Button2_Click(object sender, EventArgs e)
    {
       Button1.Attributes.Add(
"onclick""javascript:if(confirm('确定')) "+
                                         
"{ document.forms[0]['TextBox1'].value= 'ok';}"+
                                          
" else"+
                                          
" { document.forms[0]['TextBox1'].value= 'no'}");     
   
    }
    
protected void Button1_Click(object sender, EventArgs e)
    {
        
if (TextBox1.Text == "ok")
        {
            Response.Write(
"<script type ='text/javascript'> alert('执行确定的处理')</script>");
            TextBox1.Text 
= "";
        }
        
else
        {
            
if(TextBox1.Text == "no")
            {
                Response.Write(
"<script type ='text/javascript'> alert('执行否的处理')</script>");
                TextBox1.Text 
= "";
            }
        }

ExpandedBlockStart.gif
 1  protected void Page_Load(object sender, EventArgs e)
 2     {
 3 
 4     }
 5     protected void Button2_Click(object sender, EventArgs e)
 6     {
 7        Button1.Attributes.Add("onclick""javascript:if(confirm('确定')) "+
 8                                          "{ document.forms[0]['TextBox1'].value= 'ok';}"+
 9                                           " else"+
10                                           " { document.forms[0]['TextBox1'].value= 'no'}");     
11    
12     }
13     protected void Button1_Click(object sender, EventArgs e)
14     {
15         if (TextBox1.Text == "ok")
16         {
17             Response.Write("<script type ='text/javascript'> alert('执行确定的处理')</script>");
18             TextBox1.Text = "";
19         }
20         else
21         {
22             if(TextBox1.Text == "no")
23             {
24                 Response.Write("<script type ='text/javascript'> alert('执行否的处理')</script>");
25                 TextBox1.Text = "";
26             }
27         }
28 

ExpandedBlockStart.gif
 protected void Button2_Click(object sender, EventArgs e)
    {
       Button1.Attributes.Add(
"onclick""javascript:if(confirm('确定')) "+
                                         
"{ document.forms[0]['TextBox1'].value= 'ok';}"+
                                          
" else"+
                                          
" { document.forms[0]['TextBox1'].value= 'no'}");
       Button1.Text 
= " 有confirm";
   
    }
 
protected void Button1_Click(object sender, EventArgs e)
    {
        
if (TextBox1.Text == "ok")
        {
            Response.Write(
"<script type ='text/javascript'> alert('执行确定的处理')</script>");
            TextBox1.Text 
= "";
        }
        
else
        {
            
if (TextBox1.Text == "no")
            {
                Response.Write(
"<script type ='text/javascript'> alert('执行否的处理')</script>");
                TextBox1.Text 
= "";
            }
            
else
            {
                Response.Write(
"<script type ='text/javascript'> alert('先点击“赋值按钮”')</script>");
            }
        }
        

ExpandedBlockStart.gif
protected void Button2_Click(object sender, EventArgs e)
    {
       Button1.Attributes.Add(
"onclick""javascript:if(confirm('确定')) "+
                                         
"{ document.forms[0]['TextBox1'].value= 'ok';}"+
                                          
" else"+
                                          
" { document.forms[0]['TextBox1'].value= 'no'}");
       Button1.Text 
= " 有confirm";
   
    }
    
protected void Button1_Click(object sender, EventArgs e)
    {
        
if (TextBox1.Text == "ok")
        {
            Response.Write(
"<script type ='text/javascript'> alert('执行确定的处理')</script>");
            TextBox1.Text 
= "";
        }
        
else
        {
            
if (TextBox1.Text == "no")
            {
                Response.Write(
"<script type ='text/javascript'> alert('执行否的处理')</script>");
                TextBox1.Text 
= "";
            }
            
else
            {
                Response.Write(
"<script type ='text/javascript'> alert('先点击“赋值按钮”')</script>");
            }
        }
        


ContractedBlock.gif ExpandedBlockStart.gif aspx.cs中主要代码
protected void Button2_Click(object sender, EventArgs e)
    {
       Button1.Attributes.Add(
"onclick""javascript:if(confirm('确定')) "+
                                         
"{ document.forms[0]['TextBox1'].value= 'ok';}"+
                                          
" else"+
                                          
" { document.forms[0]['TextBox1'].value= 'no'}");
       Button1.Text 
= " 有confirm";
   
    }
    
protected void Button1_Click(object sender, EventArgs e)
    {
        
if (TextBox1.Text == "ok")
        {
            Response.Write(
"<script type ='text/javascript'> alert('执行确定的处理')</script>");
            TextBox1.Text 
= "";
        }
        
else
        {
            
if (TextBox1.Text == "no")
            {
                Response.Write(
"<script type ='text/javascript'> alert('执行否的处理')</script>");
                TextBox1.Text 
= "";
            }
            
else
            {
                Response.Write(
"<script type ='text/javascript'> alert('先点击“赋值按钮”')</script>");
            }
        }
        
    }

这只是提供一种简单的思路,其实也可以通过textbox的changed时间来处理的,不过这个需要postback一次

转载于:https://www.cnblogs.com/hsrzyn/archive/2009/08/18/1549353.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值