Solved

Pass URL value without changing displayed search results

Posted on 2011-02-24
11
420 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now