ASP.NET常用代码汇总

1. 打开新的窗口并传送参数:
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")

2.跳转到新页面

Response.Write("<script>window.location='http://www.51aspx.com/bizpulic/upmeb.aspx'</script>");

3.为按钮添加对话框

在aspx前台页面:

<asp:Button ID="btn1" runat="server" Text="按钮1" onclick="btn1_Click"  OnClientClick="return confirm('确认删除活动吗?')" />

在cs后台文件:

Button1.Attributes.Add("onclick","return confirm('确认?')");

button.attributes.add("onclick","if(confirm('are you sure...?')){return true;}else{return false;}")

4.删除文件

string filename ="20059595157517.jpg";
pub.util.DeleteFile(HttpContext.Current.Server.MapPath("../file/")+filename);

你可能感兴趣的:(asp.net)