Solved

Pass URL value without changing displayed search results

Posted on 2011-02-24
11
430 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:derrekdeveloper
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34974931
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.
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34974983
Here is an example:

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

Open in new window

0
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 500 total points
ID: 34974988
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:mayank_joshi
ID: 34978952
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

0
 
LVL 4

Expert Comment

by:abhinayp
ID: 34982619
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.
0
 

Author Comment

by:derrekdeveloper
ID: 34982756
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.
0
 
LVL 4

Expert Comment

by:abhinayp
ID: 34983371
   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
0
 

Author Comment

by:derrekdeveloper
ID: 34983504
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>
0
 
LVL 4

Expert Comment

by:abhinayp
ID: 34983693
Just making sure if i understood correctly.

displayValues contains ur final results and u are displaying it using Label3. Right?
0
 
LVL 4

Expert Comment

by:abhinayp
ID: 34983736
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

0
 

Author Comment

by:derrekdeveloper
ID: 34983839
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.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What are the simplest ways to create a Merge Sort? 3 37
ASP.NET Content Page 3 52
Securing WEBAPI on Azure 2 28
Calculating percentage 2 32
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question