RegisterClientScriptBlock不起作用 [英] RegisterClientScriptBlock not working

查看:156
本文介绍了RegisterClientScriptBlock不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件上传控件:

I have a fileupload control:

<asp:FileUpload ID="file" runat="server" Width="100%" />


然后,我在后面的代码中注册了一些JavaScript:


Then I register some javascript in the codebehind:

this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "file", "<script language=javascript> function BrowseClick() { "
  + "document.getElementById('" + this.file.ClientID.ToString() + "').click(); return false; } </script>");


然后,将函数添加到ASP.NET按钮的属性中:


Then I add the function to the attributes of an ASP.NET button:

this.btnDownload.Attributes.Add("onclick", "BrowseClick");


当我单击此按钮时,我希望打开文件对话框,但是什么也没有发生.为什么?
另外,我希望文件上传以另存为"对话框而不是文件打开"对话框打开.


When I click this button I expect a file dialog to open, but nothing happens. Why?
Also, I want the fileupload to open as a "save as" dialog instead of a "file open" dialog. How can this be done?

推荐答案

看看这篇文章,听起来就像您需要的一样:
使用C#下载文件 [
Have a look at this article, sounds like the same thing you need:
File download using C# [^]

It says, for SaveAs dialog in ASP.NET you need to add these to the response header:
Response.ContentType="application/ms-word";
Response.AddHeader( "content-disposition","attachment; filename=download.doc");


这篇关于RegisterClientScriptBlock不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆