-2
 function DownloadImage() { 
     var imagepath=  $("input[id$=hdn_Downloadpath]").val()

        <% Dim filePath As String = ConfigurationManager.AppSettings("Convention_IagesPath") & "images/"%> + imagepath.ToString()

        <%  Response.ContentType = "image/jpg"%>

        <%  Response.AddHeader("Content-Disposition", "attachment;filename=""" & filePath & """")%>

        <% Response.TransmitFile(filePath)%>

        <% Response.End()%>

}

我如何在 java 脚本中调用 vb 代码。还有一个问题是当页面被调用时,这段代码也会执行,因此它会产生错误

4

1 回答 1

0

It doesn't work like that. Javascript is client side and VB is server side. You'll need to find a way to call the server back, by doing a post/get or ajax.

In your case, you could have your javascript like this

function DownloadImage() { 
    var imagepath=  $("input[id$=hdn_Downloadpath]").val()

    window.location="some_page.aspx?imagePath=" + imagepath;
}

And have a page, called some_page.aspx with this code

Dim filePath As String = ConfigurationManager.AppSettings("Convention_IagesPath") & "images/" + Request.QueryString("imagePath")

Response.ContentType = "image/jpg"
Response.AddHeader("Content-Disposition", "attachment;filename=""" & filePath & """")
Response.TransmitFile(filePath)
Response.End()

* This is an example

于 2013-09-03T14:20:03.943 回答