I have a user control, named productslist.ascx.
On pruductslist.ascx, I am using Entity Datasource and a
QUERY EXTENDER and LISTview.
I have a page Defualt.aspx. On Defualt.aspx, I have a TEXTBOX with a
SUBMIT button for searching the site.
Everthing works fine so far, AS LONG as the results of the Search is posted back to
Default.aspx.
What I want is for the results of the search to be posted on a different page.
So I created a new page, Results.aspx and set the postback url to it. What I want is that when a user clicks the Submit button, after entering a search string, the text the entered is used to execute the query on
Productslist.ascx and the results displayed on RESULTS.ASPX. Again, everything works fine as long as the results are posted on same page hosting the usercontrol,
BUT I want the postback url to be a different page. I am coding in VB and VS 2010.
cheers,
yousaid
Currently, how have you set up your QueryExtender ? (I mean what type of Expression)
You would be able to handle the OnClick or OnCommand event and use Response.Redirect(string.Format("results.aspx?criteria={0}", TextBox1.Text)) to redirect to 'results.aspx' concatenating the value (.Text property) of the search Textbox. On the results page
you'd get the value from Request.QueryString["criteria"]
Thanks for your reply, but it does not work. Same results as I had before posting. When clicked, the onclick fires and redirects me to Results.aspx, but it does not append the Text entered into the TextBox1 to the QueryStrings. No exceptions are Thrown either.
Here is my QueryExtender;
On the Products.ascx user control that is on Results.aspx, I have this on the Code behind page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Textbox1 As TextBox = CType(Page.FindControlRecursive("Textbox1"), TextBox)
If Not IsPostBack Then
lvProducts.DataBind()
End If
End Sub
Like I said, If I view Results.aspx directly and enter a search string it works fine. So the problem here seems to be that the Search Strings
are not being appended to the querystring.
I have tried with both Button and ImageButton but same results.
My Imagebutton looks like this
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click"
ImageUrl="~/images/searchicon.gif" PostBackUrl="~/Results.aspx" />
Codebehind
------------
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
' Dim SearchTextbox As TextBox = CType(Page.FindControlRecursive("SearchTextbox"), TextBox)
Response.Redirect(String.Format("Results.aspx?criteria={0}", TextBox1.Text))
yousaid
Member
715 Points
278 Posts
Entity Datasource and Query Extender using LISTVIEW.
Mar 09, 2011 01:26 PM|LINK
I have a user control, named productslist.ascx.
On pruductslist.ascx, I am using Entity Datasource and a QUERY EXTENDER and LISTview.
I have a page Defualt.aspx. On Defualt.aspx, I have a TEXTBOX with a SUBMIT button for searching the site.
Everthing works fine so far, AS LONG as the results of the Search is posted back to Default.aspx.
What I want is for the results of the search to be posted on a different page.
So I created a new page, Results.aspx and set the postback url to it.
What I want is that when a user clicks the Submit button, after entering a search string, the text the entered is used to execute the query on Productslist.ascx and the results displayed on RESULTS.ASPX. Again, everything works fine as long as the results are posted on same page hosting the usercontrol, BUT I want the postback url to be a different page.
I am coding in VB and VS 2010.
cheers,
yousaid
PeteNet
All-Star
81342 Points
11398 Posts
Re: Entity Datasource and Query Extender using LISTVIEW.
Mar 09, 2011 03:23 PM|LINK
Currently, how have you set up your QueryExtender ? (I mean what type of Expression)
You would be able to handle the OnClick or OnCommand event and use Response.Redirect(string.Format("results.aspx?criteria={0}", TextBox1.Text)) to redirect to 'results.aspx' concatenating the value (.Text property) of the search Textbox. On the results page you'd get the value from Request.QueryString["criteria"]
Peter
yousaid
Member
715 Points
278 Posts
Re: Entity Datasource and Query Extender using LISTVIEW.
Mar 10, 2011 12:40 AM|LINK
Thanks for your reply, but it does not work. Same results as I had before posting. When clicked, the onclick fires and redirects me to Results.aspx, but it does not append the Text entered into the TextBox1 to the QueryStrings. No exceptions are Thrown either. Here is my QueryExtender;
<asp:QueryExtender ID="QueryExtlocate" runat="server" TargetControlID="EdsProductsSearch">
<asp:SearchExpression SearchType="StartsWith" DataFields="ProductName">
<asp:ControlParameter ControlID="TextBox1" />
</asp:SearchExpression>
<asp:OrderByExpression DataField="ProductName" Direction="Ascending">
<asp:ThenBy DataField="Unitcost" Direction="Ascending" />
</asp:OrderByExpression>
</asp:QueryExtender>
On the Products.ascx user control that is on Results.aspx, I have this on the Code behind page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Textbox1 As TextBox = CType(Page.FindControlRecursive("Textbox1"), TextBox)
If Not IsPostBack Then
lvProducts.DataBind()
End If
End Sub
Like I said, If I view Results.aspx directly and enter a search string it works fine. So the problem here seems to be that the Search Strings
are not being appended to the querystring.
I have tried with both Button and ImageButton but same results.
My Imagebutton looks like this
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click"
ImageUrl="~/images/searchicon.gif" PostBackUrl="~/Results.aspx" />
Codebehind
------------
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
' Dim SearchTextbox As TextBox = CType(Page.FindControlRecursive("SearchTextbox"), TextBox)
Response.Redirect(String.Format("Results.aspx?criteria={0}", TextBox1.Text))
End Sub
Again, thanks
PeteNet
All-Star
81342 Points
11398 Posts
Re: Entity Datasource and Query Extender using LISTVIEW.
Mar 11, 2011 03:48 AM|LINK
instead of a ControlParameter you could use a QueryStringParameter:
<asp:SearchExpression....
<asp:QueryStringParameter QueryStringField="criteria" />
as long as you find the Textbox to reference it's Text property you should be seeing the value in the address bar on your browser.
and, don't set the PostBackUrl (you're going to use the Click event to Redirect):
<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; width: 100%; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin: 8px;">
</div>also, a SessionParameter would work too (you'd set a Session variable in the first page)
Peter