Getting the FilterConditions settings via a Custom Macro

Chidozie Bright asked on February 3, 2017 01:31

Here's the issue. We have a Custom Table Datasource, with a Custom Filter, with a Basic Repeater on a page. By default, when the page loads the Repeater will display all of the information it received from the DataSource. What I would like it to do is on load NOT load/display anything until a Filter (select state, for instance) is applied, which of course is on PostBack.

The direction I've been taking has been to create a Custom Macro that can get the ViewState property for the Repeater's FilterCondition (i.e. a boolean that ask is the FilterCondition null or empty) and then apply it to the visible property of the Repeater, but this doesn't seem possible. In a class the Page level element so including the System.Web.UI Namespace doesn't work, thus no access to ViewState. And there doesn't seem to be any other way to get that data.

Any suggestions?

Correct Answer

Peter Mogilnitski answered on February 3, 2017 04:13

You can make your filter pass value via query string for example and put a macro in the repeater visibility {%QueryString["FilterParameterName"] != "" {return true} {return false}|(identity)GlobalAdministrator%}

1 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on February 3, 2017 03:21

Kind of a hack but on first page load, set your where condition to something which won't return any results like 'WHERE ColumnName = 'some wierd string or value'`

Secondly, ViewState isn't available in the page lifecycle prior to the page load event. Most controls and web parts require you to set the values in the Init event or before.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 3, 2017 18:05 (last edited on December 10, 2019 02:30)

Peter has the right answer, but just to add that you can do QueryString.FilterParameterName instead of QueryString["FilterParameterName"], along with some other variations listed below for reference!

{% String.IsNullOrWhiteSpace(QueryString.FilterParameterName) |(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

Chidozie Bright answered on February 7, 2017 20:33 (last edited on February 7, 2017 20:34)

Peter's solution is right and this would work great. But one thing I didn't consider in my original question was that since because we are using an autopostback for one dropdown to show/hide another dropdown (i.e. Select country. If US then show state dropdown) this throws the solution off after the filter is applied the first time because each subsequent autopostback (like selecting a different country) keeps the querystring value intact, so the querystring in the URL is still considered 'true'. This causes the default query is run on postback and shows results prior to applying the filter again.

So in this particular case we ended up having to go with a custom module so that we had better control of the visibility of results.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.