我有一个下拉列表,在我的aspx页面上将autopostback设置为true。在我的aspx.vb页面中,当在ddl中选择了一个项目时,用户将被重定向到与他们单击的项目关联的文件。所有这一切都很好。
如果用户单击后退按钮,则会将其带回到前一个屏幕。但是,他们现在点击的任何内容都会将其重定向回他们在点击后退按钮之前选择的文件。
这是aspx页面中的ddl:
asp:ListBox ID =" lbDocuments" RUNAT ="服务器"高度=" 75"宽度=" 500"行=" 8"的AutoPostBack ="真"
以下是代码背后的选定索引更改:
Private Sub listBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDocuments.SelectedIndexChanged
Dim curItem As String = lbDocuments.SelectedItem.ToString()
Response.Redirect("file://\\networkpathoffile" & curItem)
End Sub
提前致谢!
编辑*
Page_Load - 我在顶部有几个按钮,打开一组不同的标签/文本框而不是标签菜单。
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
DisplayUn.Visible = True
DisplayAgreem.Visible = False
DisplayFin.Visible = False
DisplayDoc.Visible = False
DisplayCon.Visible = False
DisplayJur.Visible = False
End If
CreateMainTable()
End Sub
ASPX文件
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="AgreementAdmin.aspx.vb" Inherits="AgreementAdmin" %>
<%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>
asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" Runat="Server">
</asp:Content>
asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<section>
Filter by Craft Type: <asp:DropDownList ID="ddlType" runat="server" AutoPostBack="True">
<asp:ListItem>Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
<asp:ListItem>Item3</asp:ListItem>
</asp:DropDownList>
</section>
<section id="DisplayDoc" runat="server">
<asp:Table ID="tblDocuments" runat="server" Width="755px">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Label ID="lblAgreementOnFile" runat="server" Text="Agreement on File "></asp:Label></asp:TableCell>
<asp:TableCell runat="server">
<asp:TextBox ID="txtAgreementOnFile" runat="server"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Label ID="lblDocuments" runat="server" Text="Documents"></asp:Label></asp:TableCell>
<asp:TableCell runat="server">
<asp:ListBox ID="lbDocuments" runat="server" Height="75" Width="500" Rows="8" SelectionMode="Single" AutoPostBack="True" "></asp:ListBox></asp:TableCell>
</asp:TableRow>
</asp:Table>
</section>
答案 0 :(得分:0)
如果我没弄错,请不要在页面加载时自动触发selectedIndexChanged事件?为什么不指定默认值(或索引0处的值)不会触发重定向?
Private Sub listBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDocuments.SelectedIndexChanged
Dim curItem As String = lbDocuments.SelectedItem.ToString()
lbDocuments.ClearSelection()
If lbDocuments.SelectedItem <> 0 Then
Response.Redirect("file://\networkpathoffile" & curItem)
End If
End Sub
答案 1 :(得分:-1)
问题可能是由于单击后退时ListBox中所选项目仍然选中而导致的。尝试在response.redirect之前清除选择:
Private Sub listBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbDocuments.SelectedIndexChanged
Dim curItem As String = lbDocuments.SelectedItem.ToString()
lbDocuments.ClearSelection()
Response.Redirect("file://\\networkpathoffile" & curItem)
End Sub