Re: Passing query string param to filter expression on ObjectDataSource
If you are using OOTB search web part then you can do this in client side, get the query string in js and then do a redirection to the target page with the query string value Cheers, Prashanth Sent from my iPhone On Sep 1, 2014, at 1:58 PM, Paul Noone p.no...@keller.com.au wrote: Hi all, I have a custom people search web part which uses a simple form, SPGrid and a DataTable. image003.jpg I’d like to extend this so that people can search for staff from another page via a Search Box. image004.png …where k=”Paul… What I want to do is: 1. Check if the k param has a value. 2. Use it in my query and apply it to the datasource’s filter expression. 3. Clear the query string on postback. I’ve added the following to the OnLoad event but it throws a NullReference exception. Any help appreciated. // Get URL and check for k query string param in case of search from another page String txtNameFromQuery = HttpContext.Current.Request.QueryString[k]; if(!String.IsNullOrEmpty(txtNameFromQuery)) { // Set txtName field to query string value for additional searches txtName.Text = txtNameFromQuery; // Define the search query String q = Name LIKE '% + txtNameFromQuery + %'; // Apply query to filterexpression ds.FilterExpression = q; ViewState[FilterExpression] = (String)ds.FilterExpression; // Remove any query string parameters from the URL HttpContext.Current.Request.QueryString.Clear(); } Regards, Paul The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any responsibility for viruses and it is your responsibility to scan the email and attachments (if any). Visit http://www.keller.com.au/ for more information. This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
RE: Passing query string param to filter expression on ObjectDataSource
Hi Prashanth, Redirecting to the target page and appending the query is no problem. However the Staff Lookup web part on the target page is a custom part. I want to perform a search on page load if the key/value is present and then clear it on postback. Hope that makes sense. Regards, Paul From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Prashanth Thiyagalingam Sent: Monday, 1 September 2014 8:11 PM To: ozMOSS Subject: Re: Passing query string param to filter expression on ObjectDataSource If you are using OOTB search web part then you can do this in client side, get the query string in js and then do a redirection to the target page with the query string value Cheers, Prashanth Sent from my iPhone On Sep 1, 2014, at 1:58 PM, Paul Noone p.no...@keller.com.aumailto:p.no...@keller.com.au wrote: Hi all, I have a custom people search web part which uses a simple form, SPGrid and a DataTable. image003.jpg I’d like to extend this so that people can search for staff from another page via a Search Box. image004.png …where k=”Paul… What I want to do is: 1. Check if the k param has a value. 2. Use it in my query and apply it to the datasource’s filter expression. 3. Clear the query string on postback. I’ve added the following to the OnLoad event but it throws a NullReference exception. Any help appreciated. // Get URL and check for k query string param in case of search from another page String txtNameFromQuery = HttpContext.Current.Request.QueryString[k]; if(!String.IsNullOrEmpty(txtNameFromQuery)) { // Set txtName field to query string value for additional searches txtName.Text = txtNameFromQuery; // Define the search query String q = Name LIKE '% + txtNameFromQuery + %'; // Apply query to filterexpression ds.FilterExpression = q; ViewState[FilterExpression] = (String)ds.FilterExpression; // Remove any query string parameters from the URL HttpContext.Current.Request.QueryString.Clear(); } Regards, Paul The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any responsibility for viruses and it is your responsibility to scan the email and attachments (if any). Visit http://www.keller.com.au/ for more information. This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.commailto:ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any responsibility for viruses and it is your responsibility to scan the email and attachments (if any). Visit http://www.keller.com.au/ for more information. This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
RE: Passing query string param to filter expression on ObjectDataSource
Paul, HttpContext.Current.Request.QueryString.Clear(); This will clear the querystring on the request object that is about to be destroyed, so is probably not going to be a strategy that will work. You might want to look into modifying the response object, but probably more likely to succeed is something like thishttp://blogs.msdn.com/b/tinghaoy/archive/2005/12/22/506852.aspx where you can alter the query string by setting the PostBackUrl on the search button on your page. Cheers, J. James Boman ■ Phone: +61872001100callto:+61872001100 ■ Mobile: +61417857298callto:+61417857298 ■ Skype: JDBomancallto:JDBoman ■ Web: www.ipmo.com.auhttp://www.ipmo.com.au/ From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Tuesday, 2 September 2014 8:45 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Hi Prashanth, Redirecting to the target page and appending the query is no problem. However the Staff Lookup web part on the target page is a custom part. I want to perform a search on page load if the key/value is present and then clear it on postback. Hope that makes sense. Regards, Paul From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Prashanth Thiyagalingam Sent: Monday, 1 September 2014 8:11 PM To: ozMOSS Subject: Re: Passing query string param to filter expression on ObjectDataSource If you are using OOTB search web part then you can do this in client side, get the query string in js and then do a redirection to the target page with the query string value Cheers, Prashanth Sent from my iPhone On Sep 1, 2014, at 1:58 PM, Paul Noone p.no...@keller.com.aumailto:p.no...@keller.com.au wrote: Hi all, I have a custom people search web part which uses a simple form, SPGrid and a DataTable. image003.jpg I’d like to extend this so that people can search for staff from another page via a Search Box. image004.png …where k=”Paul… What I want to do is: 1. Check if the k param has a value. 2. Use it in my query and apply it to the datasource’s filter expression. 3. Clear the query string on postback. I’ve added the following to the OnLoad event but it throws a NullReference exception. Any help appreciated. // Get URL and check for k query string param in case of search from another page String txtNameFromQuery = HttpContext.Current.Request.QueryString[k]; if(!String.IsNullOrEmpty(txtNameFromQuery)) { // Set txtName field to query string value for additional searches txtName.Text = txtNameFromQuery; // Define the search query String q = Name LIKE '% + txtNameFromQuery + %'; // Apply query to filterexpression ds.FilterExpression = q; ViewState[FilterExpression] = (String)ds.FilterExpression; // Remove any query string parameters from the URL HttpContext.Current.Request.QueryString.Clear(); } Regards, Paul The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any responsibility for viruses and it is your responsibility to scan the email and attachments (if any). Visit http://www.keller.com.au/ for more information. This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.commailto:ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any responsibility for viruses and it is your responsibility to scan the email and attachments (if any). Visit http://www.keller.com.au/ for more information. This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
RE: Passing query string param to filter expression on ObjectDataSource
That makes sense. I initially had it redirecting. Would it be just as good to add the query string check into the click handler for the Search button? if (!String.IsNullOrEmpty(queryString)) { Button1.PostBackUrl = queryString; } And would Request.QueryString.Remove(k) be just as effective? Regards, Paul From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of James Boman Sent: Tuesday, 2 September 2014 9:51 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Paul, HttpContext.Current.Request.QueryString.Clear(); This will clear the querystring on the request object that is about to be destroyed, so is probably not going to be a strategy that will work. You might want to look into modifying the response object, but probably more likely to succeed is something like thishttp://blogs.msdn.com/b/tinghaoy/archive/2005/12/22/506852.aspx where you can alter the query string by setting the PostBackUrl on the search button on your page. Cheers, J. James Boman ■ Phone: +61872001100callto:+61872001100 ■ Mobile: +61417857298callto:+61417857298 ■ Skype: JDBomancallto:JDBoman ■ Web: www.ipmo.com.auhttp://www.ipmo.com.au/ From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Tuesday, 2 September 2014 8:45 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Hi Prashanth, Redirecting to the target page and appending the query is no problem. However the Staff Lookup web part on the target page is a custom part. I want to perform a search on page load if the key/value is present and then clear it on postback. Hope that makes sense. Regards, Paul From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Prashanth Thiyagalingam Sent: Monday, 1 September 2014 8:11 PM To: ozMOSS Subject: Re: Passing query string param to filter expression on ObjectDataSource If you are using OOTB search web part then you can do this in client side, get the query string in js and then do a redirection to the target page with the query string value Cheers, Prashanth Sent from my iPhone On Sep 1, 2014, at 1:58 PM, Paul Noone p.no...@keller.com.aumailto:p.no...@keller.com.au wrote: Hi all, I have a custom people search web part which uses a simple form, SPGrid and a DataTable. image003.jpg I’d like to extend this so that people can search for staff from another page via a Search Box. image004.png …where k=”Paul… What I want to do is: 1. Check if the k param has a value. 2. Use it in my query and apply it to the datasource’s filter expression. 3. Clear the query string on postback. I’ve added the following to the OnLoad event but it throws a NullReference exception. Any help appreciated. // Get URL and check for k query string param in case of search from another page String txtNameFromQuery = HttpContext.Current.Request.QueryString[k]; if(!String.IsNullOrEmpty(txtNameFromQuery)) { // Set txtName field to query string value for additional searches txtName.Text = txtNameFromQuery; // Define the search query String q = Name LIKE '% + txtNameFromQuery + %'; // Apply query to filterexpression ds.FilterExpression = q; ViewState[FilterExpression] = (String)ds.FilterExpression; // Remove any query string parameters from the URL HttpContext.Current.Request.QueryString.Clear(); } Regards, Paul The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any responsibility for viruses and it is your responsibility to scan the email and attachments (if any). Visit http://www.keller.com.au/ for more information. This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal ___ Sponsored by Infotext - Amazing Search for Microsoft SharePoint - http://www.infotext.com/ ozmoss mailing list ozmoss@ozmoss.commailto:ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss The content of this email is confidential to the intended recipient at the email address to which it has been addressed. It may not be disclosed to, or used by, anyone other than this addressee, nor may it be copied in any way. If received in error, please contact the author and then delete the message from your system. Please note that neither Keller Australia nor the sender accepts any
RE: Passing query string param to filter expression on ObjectDataSource
Paul I think the click handler would be too late. I think you want to do it in the initial pre-render The life cycle would then be: 1. User clicks search in search webpart, cause navigation to URL with k in query string 2. Your onload/prerender runs, receives the k param, filters the dataset, renders the result back out to the user, sets the postbackurl on the search button (k param is visible in the URL bar at this point) 3. User clicks on the search button in your custom webpart, the postback url does not include the k param because it has a custom postback url. 4. Your onload/prerender runs (there is no k param this time), normal search activities are processed and results rendered to the user. (k param disappears) If the objective is for the user ever to see the k parameter then you can add to the above solution with javascript to hide it using pushstatehttps://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history: Example: Suppose http://mozilla.org/foo.html executes the following JavaScript: var stateObj = { foo: bar }; history.pushState(stateObj, page 2, bar.html); This will cause the URL bar to display http://mozilla.org/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists. Cheers, James. James Boman ■ Phone: +61872001100callto:+61872001100 ■ Mobile: +61417857298callto:+61417857298 ■ Skype: JDBomancallto:JDBoman ■ Web: www.ipmo.com.auhttp://www.ipmo.com.au/ From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Tuesday, 2 September 2014 9:38 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource That makes sense. I initially had it redirecting. Would it be just as good to add the query string check into the click handler for the Search button? if (!String.IsNullOrEmpty(queryString)) { Button1.PostBackUrl = queryString; } And would Request.QueryString.Remove(k) be just as effective? Regards, Paul From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of James Boman Sent: Tuesday, 2 September 2014 9:51 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Paul, HttpContext.Current.Request.QueryString.Clear(); This will clear the querystring on the request object that is about to be destroyed, so is probably not going to be a strategy that will work. You might want to look into modifying the response object, but probably more likely to succeed is something like thishttp://blogs.msdn.com/b/tinghaoy/archive/2005/12/22/506852.aspx where you can alter the query string by setting the PostBackUrl on the search button on your page. Cheers, J. James Boman ■ Phone: +61872001100callto:+61872001100 ■ Mobile: +61417857298callto:+61417857298 ■ Skype: JDBomancallto:JDBoman ■ Web: www.ipmo.com.auhttp://www.ipmo.com.au/ From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Tuesday, 2 September 2014 8:45 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Hi Prashanth, Redirecting to the target page and appending the query is no problem. However the Staff Lookup web part on the target page is a custom part. I want to perform a search on page load if the key/value is present and then clear it on postback. Hope that makes sense. Regards, Paul From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Prashanth Thiyagalingam Sent: Monday, 1 September 2014 8:11 PM To: ozMOSS Subject: Re: Passing query string param to filter expression on ObjectDataSource If you are using OOTB search web part then you can do this in client side, get the query string in js and then do a redirection to the target page with the query string value Cheers, Prashanth Sent from my iPhone On Sep 1, 2014, at 1:58 PM, Paul Noone p.no...@keller.com.aumailto:p.no...@keller.com.au wrote: Hi all, I have a custom people search web part which uses a simple form, SPGrid and a DataTable. image003.jpg I’d like to extend this so that people can search for staff from another page via a Search Box. image004.png …where k=”Paul… What I want to do is: 1. Check if the k param has a value. 2. Use it in my query and apply it to the datasource’s filter expression. 3. Clear the query string on postback. I’ve added the following to the OnLoad event but it throws a NullReference exception. Any help appreciated. // Get URL and check for k query string param in case of search from another page String txtNameFromQuery = HttpContext.Current.Request.QueryString[k]; if(!String.IsNullOrEmpty(txtNameFromQuery)) { // Set txtName field to query string
RE: Passing query string param to filter expression on ObjectDataSource
Yes, of course. OnPreRender lets me modify the controls after CreateChildControls. Thanks. Not worried about the user seeing it at all. Just wanting to remove it after the query has it. So I now have the following and it’s working like a charm. Thanks, James! protected override void OnInit(EventArgs e) { base.OnInit(e); // Set query string keyword var if it exists txtNameFromQuery = HttpContext.Current.Request.QueryString[k]; } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!String.IsNullOrEmpty(txtNameFromQuery)) { // Set txtName field to query string value for additional searches txtName.Text = txtNameFromQuery; // Define the search query String q = Name LIKE '% + txtNameFromQuery + %'; // Apply query to filterexpression ds.FilterExpression = q; ViewState[FilterExpression] = (String)ds.FilterExpression; // Set clean postback URL to clear query string String pageUrl = SPContext.Current.Web.Url + SPContext.Current.File.Url; btnSearch.PostBackUrl = pageUrl; btnClear.PostBackUrl = pageUrl; } } Regards, Paul From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of James Boman Sent: Tuesday, 2 September 2014 10:23 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Paul I think the click handler would be too late. I think you want to do it in the initial pre-render The life cycle would then be: 1. User clicks search in search webpart, cause navigation to URL with k in query string 2. Your onload/prerender runs, receives the k param, filters the dataset, renders the result back out to the user, sets the postbackurl on the search button (k param is visible in the URL bar at this point) 3. User clicks on the search button in your custom webpart, the postback url does not include the k param because it has a custom postback url. 4. Your onload/prerender runs (there is no k param this time), normal search activities are processed and results rendered to the user. (k param disappears) If the objective is for the user ever to see the k parameter then you can add to the above solution with javascript to hide it using pushstatehttps://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history: Example: Suppose http://mozilla.org/foo.html executes the following JavaScript: var stateObj = { foo: bar }; history.pushState(stateObj, page 2, bar.html); This will cause the URL bar to display http://mozilla.org/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists. Cheers, James. James Boman ■ Phone: +61872001100callto:+61872001100 ■ Mobile: +61417857298callto:+61417857298 ■ Skype: JDBomancallto:JDBoman ■ Web: www.ipmo.com.auhttp://www.ipmo.com.au/ From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Tuesday, 2 September 2014 9:38 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource That makes sense. I initially had it redirecting. Would it be just as good to add the query string check into the click handler for the Search button? if (!String.IsNullOrEmpty(queryString)) { Button1.PostBackUrl = queryString; } And would Request.QueryString.Remove(k) be just as effective? Regards, Paul From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of James Boman Sent: Tuesday, 2 September 2014 9:51 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Paul, HttpContext.Current.Request.QueryString.Clear(); This will clear the querystring on the request object that is about to be destroyed, so is probably not going to be a strategy that will work. You might want to look into modifying the response object, but probably more likely to succeed is something like thishttp://blogs.msdn.com/b/tinghaoy/archive/2005/12/22/506852.aspx where you can alter the query string by setting the PostBackUrl on the search button on your page. Cheers, J. James Boman ■ Phone: +61872001100callto:+61872001100 ■ Mobile: +61417857298callto:+61417857298 ■ Skype: JDBomancallto:JDBoman ■ Web: www.ipmo.com.auhttp://www.ipmo.com.au/ From: ozmoss-boun...@ozmoss.commailto:ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of Paul Noone Sent: Tuesday, 2 September 2014 8:45 AM To: ozMOSS Subject: RE: Passing query string param to filter expression on ObjectDataSource Hi Prashanth, Redirecting to the target page and appending the query is no problem. However the Staff Lookup web part on the target page is a custom