int x=0;
Response.Write(" <script>confirm('dd') </script>"); 
上面的语句是一个对话框,有两个选择,一个是"确定",一个是"取消"。请问一下,我点"确定"就执行下面语句: 
x=1;
点"取消"就执行下面语句: 
x=2; 
请问一下高手代码怎么写?或能不能实现? 
先谢谢了。

解决方案 »

  1.   

    写function,确定用onClick事件,在function里面写具体的算法
      

  2.   

    在给你点代码参考一下吧//源里面的代码
    <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Button" OnClientClick="return confirm('你还要执行下面的操作码?')" Width="113px" />//后台执行的操作
     protected void Button4_Click(object sender, EventArgs e)
        {
            int x = 4;
            Response.Write(x);
        }
      

  3.   

    Button.Attributes.Add("onclick", "return confirm('确定吗?');");试试看
      

  4.   

    this.button1.Attributes.Add("onclick", "return confirm('确认删除吗?')");
    但是在点击取消之后就不往下执行了
      

  5.   

    jueyingfd 
    可是这个对话框并不是在点击按纽后触发的。
      

  6.   

    我这个是点击GridView中的一个buttonfield而触发的,而且有几列都是buttonfield,而且有多行。
      

  7.   

     CommandField cf = new CommandField();
                    cf.HeaderText = "Delete";
                    cf.ButtonType = ButtonType.Link;
                    cf.DeleteText = "<img border=\"0px\" onclick=\"return confirm(' Do you Confirm Delete')\" src=\"images/del.gif \" />";
                    cf.ShowDeleteButton = true;
                    ScheduleGrid.Columns.Add(cf);
      

  8.   

    C#代码:
     
       protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "FinePaste")
            {            
                int rownumsFP = Int32.Parse((String)e.CommandArgument);
                //var AA = item.parentElement.parentElement.ChildNodes[0].innerText; 
                //GridView1.Rows[0].Cells[0].Text
                int rowIndexFP = Convert.ToInt32(GridView1.Rows[rownumsFP].Cells[0].Text);
                sqlstore.SetFinePaste(rowIndexFP);           
            }
            if (e.CommandName == "TopPosts")
            {
                int rownumsTP = Int32.Parse((String)e.CommandArgument);
                //var AA = item.parentElement.parentElement.ChildNodes[0].innerText; 
                //GridView1.Rows[0].Cells[0].Text
                int rowIndexTP = Convert.ToInt32(GridView1.Rows[rownumsTP].Cells[0].Text);
                sqlstore.SetTopPosts(rowIndexTP);
            }
            if (e.CommandName == "EditPosts")
            {
     
            }
            if (e.CommandName == "DeletePosts")
            {
                int rownumsDP = Int32.Parse((String)e.CommandArgument);
                int rowIndexDP = Convert.ToInt32(GridView1.Rows[rownumsDP].Cells[0].Text);
                sqlstore.DeletePosts(rowIndexDP);//这是删除函数.                    
            }
        }asp.net代码 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataSourceID="SqlDataSource1" Height="170px" style="font-size: small" 
                Width="960px" onselectedindexchanged="GridView1_SelectedIndexChanged" 
                onrowcommand="GridView1_RowCommand1" >
                <Columns>
                    <asp:BoundField DataField="ARITICLEID" HeaderText="序号" 
                        SortExpression="ARITICLEID" />
                    <asp:BoundField DataField="USERNAME" HeaderText="发贴人" 
                        SortExpression="USERNAME" />
                    <asp:BoundField DataField="TITLE" HeaderText="标题" SortExpression="TITLE" />
                    <asp:BoundField DataField="RECALLHITS" HeaderText="回复" 
                        SortExpression="RECALLHITS" />
                    <asp:BoundField DataField="IP" HeaderText="IP地址" SortExpression="IP" />
                    <asp:BoundField DataField="IMAGEURL" HeaderText="相关图片" 
                        SortExpression="IMAGEURL" />
                    <asp:BoundField DataField="DATATIME" HeaderText="发贴时间" 
                        SortExpression="DATATIME" />
                    <asp:ButtonField CommandName="FinePaste" HeaderText="精品" Text="精品" 
                        DataTextField="TYPE" />
                    <asp:ButtonField CommandName="TopPosts" HeaderText="置顶" Text="置顶" 
                        DataTextField="OPLINE" />
                    <asp:ButtonField CommandName="EditPosts" HeaderText="编辑" Text="编辑" />
                    <asp:ButtonField CommandName="DeletePosts" HeaderText="删除" Text="删除" />
                </Columns>
            </asp:GridView>
    我想在删除函数给点击删除按纽的客户一个提示对话框,我是新手。
    请各位高手帮一下我,十分感谢。