如何在c#web上弹出消息框?请指教啊!急!

解决方案 »

  1.   

    这个问题几乎每天都有人问,真怪Response.Write("javascript:alert('hahahah!')");-or-<control name>.Attributes.Add("onclike"," return confirm('are you sure?')");
      

  2.   

    Reponse.Write("<script>window.alert(\"消息\")</script>");
      

  3.   

    你可以用这个和两位楼主比较一下:
    Page.RegisterStartupScript("","<script> alert('添加数据成功!')</script>");
      

  4.   

    你想什么时候、响应什么事件弹出?直接写到页面还是从后台将javascript脚本“写”到页面?还是其它?
      

  5.   

    也可以啦,都通过脚本实现的。
    <control name>.Attributes.Add("onclike"," return confirm('are you sure?')");
    这问题确实每天都有人问,多看看别人的贴呀。
      

  6.   

    我想在删除一些数据的时候给出提示,确认是否真的要删除。现在知道了,只要Page.RegisterStartupScript("","<script> alert('添加数据成功!')</script>");中把alert改为confirm就行了。
      

  7.   

    <control name>.Attributes.Add("onclike"," return confirm('are you sure?')");
    这个确实没问题啊,不过我在DataGrid里的button 中实现他似乎很困难
      

  8.   

    我也遇到同样的问题,在DataGrid里的button 中实现他似乎很困难,也许是我不懂,哪位大侠懂的,具体说说啊,最好把代码贴出来
      

  9.   

    麻烦一点你可以加引用 System.Windows.Forms.dll
    命名空间: using System.Windows.Forms.MessageBox;
    之后使用 MessageBox.Show();
    具体你可以查一下MessageBox.ShowMessageBox.Show("You must enter a name.", "Name Entry Error",
    MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
      

  10.   

    Button1.Attributes.Add("onclike"," return confirm('are you sure?')");
      

  11.   

    据我所知
    C#没法在后台直接弹出MessageBox.Show()
    可以这样试试:
    Response.Write("<Script>MsgBox "abc","abc" </Script>
      

  12.   

    Reponse.Write("<script>window.alert('消息')</script>");
      

  13.   

    Reponse.Write("<script>window.alert('消息')</script>");
      

  14.   

    楼上所列出的部分在一般控件中是可以实现,但是我所要解决的是在DataGrid中按编辑按钮时所要弹出的消息.
    现在已经解决了:
    以下是我用的代码
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemIndex>=0)
    {
    e.Item.Cells[9].Attributes["onclick"]="javascript:del_confirm()";
    }
    }
    if (Request.Form["del_statue"].ToString().Trim()=="true")
    {
    Managements.localhost.Service1 cs=new Managements.localhost.Service1();
    cs.DeleteClick1("delete from renSDAXXXB where ID='"+e.Item.Cells[0].Text+"'");
    Response.Redirect("record.aspx");
    }
    else
    return;
    在HTML设计中
    <script language=javascript>
    function del_confirm()
    {
    var returnValue=window.confirm("确定删除这条记录?");
    if(returnValue==true)
    {
    window.document.left.del_statue.value="true";
    }
    else 
    {
    window.document.left.del_statue.value="false";
    }
    }
    </script>
    且在页面添加一个hidden控件