0

I have a web tool which was built by someone else. The application queries the database based on search parameters entered in by the end user such as "part number, part status, etc". When a user hits the search page they are presented with a simple text box to enter in part numbers as well as a button which toggles the show all parameters function using JavaScript. If a user searches using a bunch of parameters, a list of parts are presented. If a user clicks a part they'll be taken to the parts description page.

Dilemma: When a user hits the parts description page and then invokes the back button they are presented with the first initial search page instead of being brought back to the list of parts. I would like for them to be brought back to the list of parts instead of having the form reset.

See Code Examples Below (any help would be greatly appreciated):

ASPX Page:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AdvancedSearch.aspx.cs" Inherits="AdvancedSearch" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1" ClientEvents-OnRequestStart="RadAjaxManager1_OnRequestStart">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="MainContainer">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="MainContainer" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" IsSticky="true" Style="position: absolute; top: 0; left: 0; height: 100%; width: 100%;" />
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script language="javascript" type="text/javascript">
            function RadAjaxManager1_OnRequestStart(ajaxManager, eventArgs) {
                try {
                    var re = new RegExp("\.DataDump$", "ig");
                    if (eventArgs.EventTarget.match(re)) {
                        eventArgs.EnableAjax = false;
                    }
                }
                catch (err) {
                    alert("RadAjaxManager1_OnRequestStart(...) " + err);
                }
            }
            function ToggleSearchOptions(sender, args) {
                if (sender.get_text() == "Show Search Options") {
                    sender.set_text("Hide Search Options");
                    document.getElementById('<%= Search_Options_Container.ClientID %>').style.display = "";
                }
                else {
                    sender.set_text("Show Search Options");
                    document.getElementById('<%= Search_Options_Container.ClientID %>').style.display = "none";
                }
                sender.set_autoPostBack(false);
            }
            function ToggleEquipment(state) {
                giTools.CheckUnCheckList('<%= Equipment_Fields.ClientID %>', state);
                giTools.CheckUnCheckList('<%= Equipment_Type.ClientID %>', state);
                giTools.CheckUnCheckList('<%= Equipment_Status.ClientID %>', state);
                if (state == true) {
                    $('#<%= Equipment_Type_All.ClientID %>').attr('checked', 'checked');
                    $('#<%= Equipment_Status_All.ClientID %>').attr('checked', 'checked');
                }
                else {
                    $('#<%= Equipment_Type_All.ClientID %>').removeAttr("checked");
                    $('#<%= Equipment_Status_All.ClientID %>').removeAttr("checked");
                }
            }
            function ToggleEquipment_Type(state) {
                giTools.CheckUnCheckList('<%= Equipment_Type.ClientID %>', state);
            }
            function ToggleEquipment_Status(state) {
                giTools.CheckUnCheckList('<%= Equipment_Status.ClientID %>', state);
            }
            function ToggleHistory(state) {
                giTools.CheckUnCheckList('<%= History_Fields.ClientID %>', state);
                giTools.CheckUnCheckList('<%= History_Status.ClientID %>', state);
                if (state == true) {
                    $('#<%= History_Status_All.ClientID %>').attr('checked', 'checked');
                }
                else {
                    $('#<%= History_Status_All.ClientID %>').removeAttr("checked");
                }
            }
            function ToggleHistory_Status(state) {
                giTools.CheckUnCheckList('<%= History_Status.ClientID %>', state);
            }
            function ToggleOTR(state) {
                giTools.CheckUnCheckList('<%= OTR_Fields.ClientID %>', state);
                giTools.CheckUnCheckList('<%= OTR_Classification.ClientID %>', state);
                if (state == true) {
                    $('#<%= OTR_Classification_All.ClientID %>').attr('checked', 'checked');
                }
                else {
                    $('#<%= OTR_Classification_All.ClientID %>').removeAttr("checked");
                }
            }
            function ToggleOTR_Classification(state) {
                giTools.CheckUnCheckList('<%= OTR_Classification.ClientID %>', state);
            }
            function ToggleDates(value) {
                $find('<%= Date_Start.ClientID %>').set_enabled(value);
                $find('<%= Date_End.ClientID %>').set_enabled(value);
            }
        </script>
    </telerik:RadCodeBlock>
    <div id="MainContainer" runat="server">
        <asp:Panel ID="Panel1" runat="server" DefaultButton="Submit">
            <table class="custom_table custom_border" cellpadding="0" cellspacing="0">
                <tr>
                    <td>Terms to Search for
                    </td>
                    <td>
                        <telerik:RadTextBox ID="SearchValue" runat="server" />
                    </td>
                    <td>
                        <telerik:RadButton ID="Submit" runat="server" Text="Search" OnClick="Submit_Click" />
                    </td>
                    <td style="text-align: center;">
                        <telerik:RadButton ID="ShowHideSearchOptions" runat="server" Text="Show Search Options" ButtonType="LinkButton" OnClientClicking="ToggleSearchOptions"
                            Width="120" />
                    </td>
                </tr>
            </table>
        </asp:Panel>
        <div id="Search_Options_Container" runat="server" style="display: none;">
            <br />
            <div class="clearfix">
                <div style="float: left;">
                    <table class="custom_table custom_border" cellpadding="0" cellspacing="0" width="210">

                        <tr>
                            <td class="custom_border_bottom" style="padding-left: 6px; padding-right: 5px;">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Search Equipment</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="Equipment_All" runat="server" Text="All" Checked="true" onclick="ToggleEquipment(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <asp:CheckBoxList ID="Equipment_Fields" runat="server">
                                    <asp:ListItem Text="TMS #" Selected="True" />
                                    <asp:ListItem Text="Assigned To" Selected="True" />
                                    <asp:ListItem Text="Issued To" Selected="True" />
                                    <asp:ListItem Text="Department" Selected="True" />
                                    <asp:ListItem Text="Manufacturer" Selected="True" />
                                    <asp:ListItem Text="Model #" Selected="True" />
                                    <asp:ListItem Text="Serial #" Selected="True" />
                                    <asp:ListItem Text="Description" Selected="True" />
                                    <asp:ListItem Text="Characteristics" Selected="True" />
                                    <asp:ListItem Text="Calibration Procedure" Selected="True" />
                                    <asp:ListItem Text="Calibration Standard" Selected="True" />
                                    <asp:ListItem Text="Calibration Interval" Selected="True" />
                                    <asp:ListItem Text="Required Accuracy" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Type</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="Equipment_Type_All" runat="server" Text="All" Checked="true" onclick="ToggleEquipment_Type(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <asp:CheckBoxList ID="Equipment_Type" runat="server">
                                    <asp:ListItem Text="Electronic" Value="1" Selected="True" />
                                    <asp:ListItem Text="Mechanical" Value="2" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Status</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="Equipment_Status_All" runat="server" Text="All" Checked="true" onclick="ToggleEquipment_Status(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <asp:CheckBoxList ID="Equipment_Status" runat="server">
                                    <asp:ListItem Text="Active" Value="1" Selected="True" />
                                    <asp:ListItem Text="NCR" Value="2" Selected="True" />
                                    <asp:ListItem Text="CBU" Value="3" Selected="True" />
                                    <asp:ListItem Text="TOS" Value="4" Selected="True" />
                                    <asp:ListItem Text="Missing" Value="5" Selected="True" />
                                    <asp:ListItem Text="Stock" Value="6" Selected="True" />
        <asp:ListItem Text="Extended" Value="7" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:CheckBoxList ID="Equipment_Status_Obsolete" runat="server">
                                    <asp:ListItem Text="Include Obsolete" Value="Include Obsolete" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="float: left; margin-left: 10px;">
                    <table class="custom_table custom_border" cellpadding="0" cellspacing="0" width="210">
                        <tr>
                            <td class="custom_border_bottom" style="padding-left: 6px; padding-right: 5px;">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Search History</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="History_All" runat="server" Text="All" Checked="True" onclick="ToggleHistory(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <asp:CheckBoxList ID="History_Fields" runat="server">
                                    <asp:ListItem Text="ID Number" Selected="True" />
                                    <asp:ListItem Text="Inspector" Selected="True" />
                                    <asp:ListItem Text="Inspector E-mail" Selected="True" />
                                    <asp:ListItem Text="Remarks" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Approval</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="History_Status_All" runat="server" Text="All" Checked="true" onclick="ToggleHistory_Status(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:CheckBoxList ID="History_Status" runat="server">
                                    <asp:ListItem Text="None" Value="0" Selected="True" />
                                    <asp:ListItem Text="Accepted" Value="1" Selected="True" />
                                    <asp:ListItem Text="Rejected" Value="2" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="float: left; margin-left: 10px;">
                    <table class="custom_table custom_border" cellpadding="0" cellspacing="0" width="210">
                        <tr>
                            <td class="custom_border_bottom" style="padding-left: 6px; padding-right: 5px;">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Search OTR</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="OTR_All" runat="server" Text="All" Checked="True" onclick="ToggleOTR(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <asp:CheckBoxList ID="OTR_Fields" runat="server">
                                    <asp:ListItem Text="ID Number" Selected="True" />
                                    <asp:ListItem Text="Submitter" Selected="True" />
                                    <asp:ListItem Text="Submitter E-mail" Selected="True" />
                                    <asp:ListItem Text="Actual accuracy" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <strong>Classification</strong>
                                        </td>
                                        <td style="text-align: right;">
                                            <strong>
                                                <asp:CheckBox ID="OTR_Classification_All" runat="server" Text="All" Checked="true" onclick="ToggleOTR_Classification(this.checked)" /></strong>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:CheckBoxList ID="OTR_Classification" runat="server">
                                    <asp:ListItem Text="Slight" Value="1" Selected="True" />
                                    <asp:ListItem Text="Significant" Value="2" Selected="True" />
                                </asp:CheckBoxList>
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="float: left; margin-left: 10px;">
                    <table class="custom_table custom_border" cellpadding="0" cellspacing="0">
                        <tr>
                            <td class="custom_border_bottom" style="padding-left: 5px;">
                                <strong>
                                    <asp:CheckBox ID="Filter_By_Date" runat="server" Text="Search by Date" onclick="ToggleDates(this.checked)" /></strong>
                            </td>
                        </tr>
                        <tr>
                            <td class="custom_border_bottom">
                                <telerik:RadDatePicker ID="Date_Start" runat="server" Enabled="false" Width="110" />
                                <telerik:RadDatePicker ID="Date_End" runat="server" Enabled="false" Width="110" />
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <br />
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <telerik:RadGrid ID="Results" runat="server" AllowPaging="true" PageSize="250" AllowSorting="true" OnItemDataBound="Results_ItemDataBound" OnNeedDataSource="Results_NeedDataSource">
                        <MasterTableView AutoGenerateColumns="false" PagerStyle-Position="TopAndBottom" CommandItemDisplay="TopAndBottom">
                            <CommandItemTemplate>
                                <div style="padding: 5px; float: right;">
                                    <telerik:RadButton ID="DataDump" runat="server" Text="Data Dump" OnClick="DataDump_Click" Skin="Outlook" />
                                </div>
                            </CommandItemTemplate>
                            <Columns>
                                <telerik:GridTemplateColumn DataField="id_label" SortExpression="id_label_length, id_label" HeaderText="ID #" HeaderStyle-Width="150">
                                    <ItemTemplate>
                                        <a href='View.aspx?id=<%# Eval("id") %>'>
                                            <%# Eval("id_label") %></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="type" HeaderText="Type" HeaderStyle-Width="120" />
                                <telerik:GridBoundColumn DataField="description" HeaderText="Description" HeaderStyle-Width="600" />
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </td>
            </tr>
        </table>
        <div style="padding-top: 10px; padding-bottom: 10px;">
            <strong>Wildcards</strong><br />
            The percent sign '%' allows for the substitution of any number characters (0, 1 or more).<br />
            The underscore '_' allows for the substitution of exactly 1 character. It is cumulative so you can use '__' to substitute 2 characters for example.
        </div>
    </div>
</asp:Content>

Link to CS: https://drive.google.com/file/d/0B-cYAOqWVWFjUnJBeC1MTFZBcjA/view?usp=sharing

It was too long to upload and I didn't know if any other way.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
jamHud
  • 93
  • 1
  • 1
  • 8
  • You could put the search parameter values in an array or ArrayList and store them in Session state. – Gregg Sep 07 '15 at 02:53
  • We may be on to something here, any direction as to how I would do that? – jamHud Sep 07 '15 at 21:29
  • Would I be able to create a button like "Back to list" which acts as a postback effectively resubmitting the form to the server for processing upon hitting the button. – jamHud Sep 07 '15 at 21:31
  • Yes. Since the parameter information is in Session it would be retained. Basically you would check your Session variable for null and if not null then cast back to an array and resubmit the query. – Gregg Sep 08 '15 at 22:13
  • Would you be able to provide a coding sample? Thanks for all your help. – jamHud Sep 09 '15 at 02:09

1 Answers1

0

You could save your parameter values like this:

 ArrayList parameterList = new ArrayList();
parameterList.Add(txtFirstParameter.Text);
parameterList.Add(txtSecondParameter.Text);

Session["parameterList"] = parameterList;

To retrieve values simply reference the Session variable and cast back to an ArrayList

var parameterList =  (ArrayList)Session["parameterList"];
var parameterOne = parameterList[0].ToString()
Gregg
  • 615
  • 6
  • 6
  • Hi Greg, I am trying to implement the code you have provided. However I have a question when I am trying to retrieve the session object values do I post the code in the button event, which is on a different page than the page where the variable has been declared. – jamHud Sep 24 '15 at 14:32
  • The Session variable is available to any page or user control in your application. Save the values in a Session variable on the page that is submitting the query. – Gregg Sep 25 '15 at 01:45