1、一个MessageBox的例子
public static void MessageBox( System.Web.UI.Page page, string msg ) { StringBuilder StrScript = new StringBuilder(); StrScript.Append( "<script language=javascript>" ); StrScript.Append( "alert('"+ msg +"');" ); StrScript.Append( "</script>" ); if ( ! page.IsStartupScriptRegistered( "MessageBox" ) ) { page.RegisterStartupScript( "MessageBox", StrScript.ToString() ); } } |
2、DataGrid删除的确认:
在ItemDataBound事件中加入如下代码:
LinkButton delLink = new LinkButton(); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { delLink = (LinkButton)(e.Item.Cells[0].Controls[0]); delLink.Attributes.Add("onClick","Javascript:return confirm('Are you sure to delete the record ?');"); } |