先看代码;
Page.RegisterStartupScript("","<script>alert('您的帐户被扣除了" + this.lblmoney.Text.ToString() + "元')</script>");
int fileupdatexiazaiID = Convert.ToInt32(Request.QueryString["id"].ToString());
int uid = int.Parse(Session["userid"].ToString());
int kejianid = fileupdatexiazaiID;
float fuM = float.Parse(this.lblmoney.Text.Trim());
int t = db.SaveInforAssinRY(uid, kejianid, fuM);
if (t != 1)
{
Page.RegisterStartupScript("test", "<script>alert('对不起,下载失败!')</script>"); }
else
{
//下载并修改下载次数
string sql = "update EduWare set downloadCount=downloadCount+1 where ID=" + fileupdatexiazaiID + "";
int x = db.ExecuteInsert(sql);
if (x > 0)
{
string Pathxia = Server.MapPath("../" + Session["zuozhe"] + "/Courseware/");
string fileName = HttpContext.Current.Server.UrlEncode(filenames1);
string filePath = Pathxia + filenames1;
//使用TransmifFile下载文件
FileInfo info = new FileInfo(filePath);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + filenames1);
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(filePath);
Response.End();
Response.Flush();
Response.Close();大家看到第一行的弹出框了吗?我想让他弹出提示框后在执行下载,可为什么他不弹出框,就直接下载了! 请高手帮忙。谢谢
Page.RegisterStartupScript("","<script>alert('您的帐户被扣除了" + this.lblmoney.Text.ToString() + "元')</script>");
int fileupdatexiazaiID = Convert.ToInt32(Request.QueryString["id"].ToString());
int uid = int.Parse(Session["userid"].ToString());
int kejianid = fileupdatexiazaiID;
float fuM = float.Parse(this.lblmoney.Text.Trim());
int t = db.SaveInforAssinRY(uid, kejianid, fuM);
if (t != 1)
{
Page.RegisterStartupScript("test", "<script>alert('对不起,下载失败!')</script>"); }
else
{
//下载并修改下载次数
string sql = "update EduWare set downloadCount=downloadCount+1 where ID=" + fileupdatexiazaiID + "";
int x = db.ExecuteInsert(sql);
if (x > 0)
{
string Pathxia = Server.MapPath("../" + Session["zuozhe"] + "/Courseware/");
string fileName = HttpContext.Current.Server.UrlEncode(filenames1);
string filePath = Pathxia + filenames1;
//使用TransmifFile下载文件
FileInfo info = new FileInfo(filePath);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + filenames1);
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(filePath);
Response.End();
Response.Flush();
Response.Close();大家看到第一行的弹出框了吗?我想让他弹出提示框后在执行下载,可为什么他不弹出框,就直接下载了! 请高手帮忙。谢谢
用这个吧。
<script>alert('您的帐户被扣除了" + this.lblmoney.Text.ToString() + "元');return false; </script>
return;
如果不行,把true 改false
加return; 后我的下载代码都不执行了
用 confirm 不就得了
后台注册的JS当然不是你想象的那样 写在下载代码上面就会先执行...
忘记了前台的onpageload()是最后执行的了吗?下载可能有个按钮点击事件吧,或者下载页面的load事件都可以啊
跟LS有的朋友说的那样写在click里面吧