我在asp.net中有一个web项目,其中我有一个仪表板,其中有前几个日期的下拉列表,当我从下拉列表中选择日期时,它会从匹配所选日期的文件夹中打开文件。我的下拉列表垂直排列一个奇怪的问题是,当我从ist下拉列表中选择日期时,它打开文件很好,当我从任何其他下拉列表中选择日期日期值时,它会打开从ist下拉列表中打开的相同文件,所有剩余的下拉列表行为相同。并且其他奇怪的问题是,当我从最后一个下拉列表开始打开文件时,当我从最后一个下拉列表中选择日期时,打开文件很好,并且当从第二个最后选择日期时它打开文件很好并且所有文件都打开了罚款,即当我开始我持续它显示问题,但当我开始最后Ist它工作正常。请告诉我有什么可能性? 我的代码如下:
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Data.SqlClient
Imports System.Diagnostics.Process
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Console
Partial Class DashBoard
Inherits System.Web.UI.Page
Protected Sub DD1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD1.SelectedIndexChanged
Response.Redirect("Reports/Daily Production and Stock Report (Crescent Ujala)/Daily Production and Stock Report (Crescent Ujala) " & DD1.SelectedValue & ".xls", True)
End Sub
Protected Sub DD2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD2.SelectedIndexChanged
Response.Redirect("Reports/Daily Production Efficiency Report (Crescent Ujala)/Daily Production Efficiency Report (Crescent Ujala) " & DD2.SelectedItem.Value.ToString & ".pdf", True)
End Sub
Protected Sub DD3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD3.SelectedIndexChanged
Response.Redirect("Reports/September Sowing Report/September Sowing Report " & DD3.SelectedItem.Value.ToString & ".ods", True)
End Sub
Protected Sub DD4_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD4.SelectedIndexChanged
Response.Redirect("Reports/September Sowing Report Area-1/September Sowing Report Area-1 " & DD4.SelectedItem.Value.ToString & ".ods", True)
End Sub
Protected Sub DD5_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dd5.SelectedIndexChanged
Response.Redirect("Reports/September Sowing Report Area-2/September Sowing Report Area-2 " & dd5.SelectedItem.Value.ToString & ".ods", True)
End Sub
Protected Sub DD6_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD6.SelectedIndexChanged
Response.Redirect("Reports/Daily P & L Cost sheet/Daily P & L Cost sheet. " & DD6.SelectedValue & ".xls", True)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
'Add Values to Dropdownlist 1
DD1.Items.Add(New ListItem("", ""))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
DD1.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
'Add Values to Dropdownlist 2
DD2.Items.Add(New ListItem("", ""))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
DD2.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
'Add Values to Dropdownlist 3
DD3.Items.Add(New ListItem("", ""))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
DD3.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
'Add Values to Dropdownlist 4
DD4.Items.Add(New ListItem("", ""))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
DD4.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
'Add Values to Dropdownlist 5
dd5.Items.Add(New ListItem("", ""))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
dd5.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
'Add Values to Dropdownlist 6
DD6.Items.Add(New ListItem("", ""))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -1, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -1, Now), "yyyy.MM.dd")))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -2, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -2, Now), "yyyy.MM.dd")))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -3, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -3, Now), "yyyy.MM.dd")))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -4, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -4, Now), "yyyy.MM.dd")))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -5, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -5, Now), "yyyy.MM.dd")))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -6, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -6, Now), "yyyy.MM.dd")))
DD6.Items.Add(New ListItem(Format(DateAdd(DateInterval.Day, -7, Now), "dd-MMM"), Format(DateAdd(DateInterval.Day, -7, Now), "yyyy.MM.dd")))
End If
End Sub
End Class
答案 0 :(得分:0)
我相信在您的浏览器中,您可能会收到打开/保存文件的提示。在这种情况下,当前的html文档(包括视图状态)将保持原样在浏览器中。因此,当由于下一个下拉选择而发生下一个回发时,ASP.NET将推断选择已更改为两个下拉列表(因为视图状态属于页面请求没有选择下拉列表)并且将试图为此提出事件。它可能会根据控制树引发事件,因此将首先引发第一个下拉列表的事件,这将打开第一个文件。同样,response.redirect将切断页面处理(并且不会处理后续事件)。这就是为什么你看到奇怪的行为 - 例如,如果你先选择DD4然后它将打开相应的文件,现在如果你选择DD5,它仍然会打开DD4文件。但是,现在如果你选择DD2,它将打开DD2的文件并再次在这种状态下,你试图打开DD3,它将打开DD2。下拉列表中的任何选择都将打开文件以选择最早的下拉列表。
补救措施很简单 - 在新窗口中打开文件。例如,将所有response.redirect
行更改为
ClientScript.RegisterStartupScript(Me.GetType(), "openfile", _
"window.open('<put your file url here>');", true)
更好的解决方案是删除自动回发和服务器端选择事件 - 而是处理java脚本中更改的选择并从那里启动文件。
更好的解决方案(IMO)是更改页面UI - 而不是使用下拉列表,为前七个日期提供下载链接(锚标记)。