0
votes

I have a drop down list with autopostback set to true on my aspx page. In my aspx.vb page, when an item is selected in the ddl, the user is redirected to the file associated with the item they clicked on. All of that works fine.

If the user clicks the back button, they are brought back to previous screen as excpected. However, anything they now click on redirects them back to the file they had selected before hitting the back button.

Here is the ddl in the aspx page:

asp:ListBox ID="lbDocuments" runat="server" Height="75" Width="500" Rows="8" AutoPostBack="True"

And here is the selected index change in the code behind:

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

Thanks in advance!

EDIT*

Page_Load--I have several buttons at the top that open a different set of labels/textboxes instead of a tab menu.

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 file

<%@ 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>
2
Can you provide your ASPX page code and Page_Load method (code behind) code?lucidgold
Added Page_Load and aspxxcrypted
See this answer: stackoverflow.com/a/35850964/9604 for hack-around.mxmissile

2 Answers

0
votes

If I'm not mistaken, don't selectedIndexChanged events automatically fire upon page loads? Why not specify that the default value (or value at index 0) does not trigger the 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()
    If lbDocuments.SelectedItem <> 0 Then
        Response.Redirect("file://\networkpathoffile" & curItem)
    End If
End Sub
-1
votes

The issue might be caused by the selected item remaining selected in the ListBox when clicking back. Try clearing the selection prior to the 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