Link to home
Start Free TrialLog in
Avatar of M.L. Martin
M.L. MartinFlag for United States of America

asked on

Pass URL value without changing displayed search results

I will explain this as best I can. When a user types in a search field (ASP Textbox field) and presses enter a list of search results are displayed if there is a match. The search results display in the second half of the page. A video will play in the top half of the page but not until a querystring is passed to the page. The querystring value comes from the list of displayed search results. When a user clicks on results from the search (ASP Hyperlink) the querystring value is passed to the same page he/she is on and a video starts playing. My major problem is when I pass the querystring value I do not want to lose the list of search results. It looks like in ASP.net the page refreshes each time you pass a new value. It's not optional to make the user click the back button to see the orginal search results. I'm assuming it has something to do with maintaining session state but I am no expert. YouTube and many other sites do this similar functionality so I figure it must be possible in ASP.Net. Please provide any guidance that you can. If you can help please also include the full code instead of a reference to the code if at all possible
Avatar of rawinnlnx9
rawinnlnx9
Flag of United States of America image

Why not just save the HTML of the tag that contains the search results and then repopulate it? If it's all asp.net you should be able to this very easily.

So use jquery and getelementbyid, then get innerhtml, then send your querystring, on the postback dump the html back in.

Or if it's all .net controls just do it in a routine before you post the querystring.
Here is an example:

client = new WebClient();
String htmlCode = client.DownloadString("http://born2code.net");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rawinnlnx9
rawinnlnx9
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use link button instead of hyperlink and on postback of hyperlink do something like:-

Response.Redirect("page1.aspx?videoid=" & videoid & "&search1=" &  txtsearch1.text & "&search2=" & txtsearch2.text)

Open in new window

Avatar of abhinayp
abhinayp

After u click a link in ur page loads completely. So its like opening a new page.
So, after u display results the first time, u need to save the search results in a session and rebind the list/grid with the results after page loads.
Or even save the textbox parameters in a session n get bake the results again.

Lemme know if i wasnt clear.
Avatar of M.L. Martin

ASKER

abhinayp:

That's exactly what I was thinking but didn't really know how to do it. I figured I need to save the search results in a session or....

I thought about if I could capture the value from the orginal search performed and then resubmit it when I pass the querystring parameter. So if a user submitted 'bicep' in their search criteria I would capture 'bicep' and submit it again. It would mean going to the database again but the user would still have the original search results on the page. I'm sure this is absolutely not the most efficient way to do this.

The better approach seems to be this:So, after u display results the first time, u need to save the search results in a session and rebind the list/grid with the results after page loads.

Problem is I don't know how to do either one.
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If Not Session("Results") Is Nothing Then
                If Not Request.QueryString("urQueryString") Is Nothing Then
                    Dim dt As New DataTable
                    dt = Session("Results")
                    GridView1.Datasource = dt
                    GridView1.DataBind()
                End If
            End If
        End If
    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim dt As New DataTable
        dt = GetResults(txtName.Text)
        Session("Results") = dt

        GridView1.Datasource = dt
        GridView1.DataBind()

    End Sub
This is where I am now. I am using the following code to get the value of the text box from the submitted form. It is correct because I see the value displayed in the label.

Dim displayValues As New StringBuilder()
        Dim postedValues As NameValueCollection = Request.Form
        Dim nextKey As String
        For i As Integer = 0 To postedValues.AllKeys.Length - 1
            nextKey = postedValues.AllKeys(i)
            If nextKey.Substring(0, 2) <> "__" Then
                displayValues.Append("<br>")
                displayValues.Append(nextKey)
                displayValues.Append(" = ")
                displayValues.Append(postedValues(i))
            End If
        Next
        Label3.Text = displayValues.ToString()

In the following code I actually pass the query string value which I have to do. What I think I need to do is modify the code below to not only pass the querystring value at it is doing but also get the value that the label is displaying and submit that as a form value if that is possible.

<asp:HyperLink ID="HyperLink45" runat="server"
 ForeColor="White"
 ImageUrl='<%# Eval("videoplaymed") %>'
 
 NavigateUrl='<%# String.Format("~/search.aspx?eid={0} ", Eval("eid")) %>'
 >
</asp:HyperLink>
Just making sure if i understood correctly.

displayValues contains ur final results and u are displaying it using Label3. Right?
If thats the case,  chk this
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If Not Session("Results") Is Nothing Then
                If Not Request.QueryString("eid") Is Nothing Then

                    Label3.Text = Session("Results").ToString()

                End If
            End If
        End If
    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        'Some code here

        Dim displayValues As New StringBuilder()
        Dim postedValues As NameValueCollection = Request.Form
        Dim nextKey As String
        For i As Integer = 0 To postedValues.AllKeys.Length - 1
            nextKey = postedValues.AllKeys(i)
            If nextKey.Substring(0, 2) <> "__" Then
                displayValues.Append("<br>")
                displayValues.Append(nextKey)
                displayValues.Append(" = ")
                displayValues.Append(postedValues(i))
            End If
        Next
        Label3.Text = displayValues.ToString()
        Session("Results") = Label3.Text

        'Some more code


    End Sub

Open in new window

Correct. I grabbed the code from the ASP.Net Forum. After looking at your code though I'm pretty sure that will work also. Let me list out the page flows.

The site is www.GoLiveFitness.com

1. From the Default.aspx page and about 5 others a user can search for exercises by entering values in a field named search whish is a asp.net textbox.

2. On the search results page called Search.aspx the results display.

3. Currently a user clicks on a image from the search results and a new 320 x 240 browser opens and starts playing a video (JW Player) which has received a querystring value passed when the user clicked on the image.

4. We have signed up 600 users in three weeks but we have received many, many complaints about playing the video in a new window and I agree. I then decided it must be possible to keep all of the image results that pass the querystring information displayed on the page even as the user selects and plays different videos.

5. My first test was to try and capture the textbox value and at least store it in a label to verify it which I did.

6. Now I'm trying to figure out how to pass the captured value from the text box and pass the querystring value from the images from the search reults.

7. I have to different SQLDataSources and Stored Procedures running on the page. One is looking for the query string to play the video. The other one is looking for the textbox value that produces the search results.