ASPX templates
Version 3.x > ASPX templates > Can't get QueryParameters to work View modes: 
User avatar
Member
Member
danielrichard-oaot - 11/7/2008 7:32:07 AM
   
Can't get QueryParameters to work
Finding documentation and examples of using QueryParameters in a QueryRepeater is frustrating. I followed what I could find and keep getting this error:

"....'ASP.cmswebparts_viewers_queryrepeater_ascx' does not contain a definition for 'QueryParameters'...."

I could assign the WhereCondition with no problems, but the QueryParameters doesn't work.

I have the following code in my .master page:
<uc1:QueryRepeater runat="server" ID="PageImage" SelectTopN="1"
TransformationName="CMS.File.ImageGallery_detail400"
QueryName="cms.file.selectPageImage" />

I have the following code in my .master.cs page:
protected void Page_Init(object sender, EventArgs e){
this.PageImage.WhereCondition = "FileDescription like '%" + Functions.GetAliasPath() + ",%'";

// Send in the Alias Path as a parameter to the query
object[,] queryParams = new object[1,3];
queryParams[0,0] = "@WhereClause";
queryParams[0,1] = Functions.GetAliasPath();
this.PageImage.QueryParameters = queryParams;

this.PageImage.ReloadData();
}

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/10/2008 7:46:24 AM
   
RE:Can't get QueryParameters to work
Hi,

The problem is that you are using the parameters in a web part and not in a control. You need to use the QueryRepeater control.

Could you please send us link to the documentation which you have followed? I was not able to find any mention that QueryParameters can be used with web part.

Thank you in advance.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
danielrichard-oaot - 11/10/2008 8:12:54 AM
   
RE:Can't get QueryParameters to work
Thanks. I guess I'm not real clear on when/why to use a web part vs. a control. I dragged/dropped the control in VS2005 and it no longer gives me that error.

User avatar
Member
Member
danielrichard-oaot - 11/10/2008 8:33:09 AM
   
RE:Can't get QueryParameters to work
So, now I have the Control setup as this:

<cc1:QueryRepeater id="PageImage" runat="server" QueryName="cms.file.selectPageImage" SelectTopN="1" TransformationName="CMS.File.ImageGallery_detail400">
</cc1:QueryRepeater>

With this in the code-behind:
object[,] queryParams = new object[1, 3];
queryParams[0, 1] = "@AliasPath";
queryParams[0, 2] = Functions.GetAliasPath();
this.PageImage.QueryParameters = queryParams;

Now, in my document type query, I have keep getting an error saying the variable @AliasPath needs to be declared:

DECLARE @PathString varchar(200)
DECLARE @ShowDefault char(1)

SET @PathString = @AliasPath
SET @ShowDefault = 'N'

-- This statement loops through the current node's alias path levels until an assigned image is found.
-- If no assigned image is found it defaults to the first image starting with the 'ppl_' prefix.

WHILE(SELECT max(FileID) FROM CONTENT_File WHERE FileDescription like '%' + @PathString + ',%') IS NULL
BEGIN
-- Check if it's the root level. If so, set the flag to display a default image and break
IF(SELECT CHARINDEX('/', REVERSE(@PathString))) = (SELECT(LEN(@PathString)))
BEGIN
SET @ShowDefault = 'Y'
BREAK
END
-- Go back one level in the path and check for an assigned image there
ELSE
BEGIN
SET @PathString = SUBSTRING(@PathString, 1, LEN(@PathString) - CHARINDEX('/', REVERSE(@PathString)))
CONTINUE
END
END

IF @ShowDefault = 'N'
SELECT ##TOPN## * FROM CONTENT_File
WHERE FileDescription like '%' + @PathString + ',%'
ELSE
SELECT ##TOPN## * FROM CONTENT_File
WHERE FileName like 'ppl_%'

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/10/2008 9:10:06 AM
   
RE:Can't get QueryParameters to work
Hi again,

Could you please modify the definition of the parameters to be like this:

queryParams[0, 0] = "@AliasPath";
queryParams[0, 1] = Functions.GetAliasPath();

Please notice that the array index stars with 0.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
danielrichard-oaot - 11/10/2008 9:20:28 AM
   
RE:Can't get QueryParameters to work
Stil a no-go. I get the same error from the query (...caused exception: Must declare the variable '@AliasPath')

(I also tried changing the new object[1,3] to [1,2])

object[,] queryParams = new object[1, 2];
queryParams[0, 0] = "@AliasPath";
queryParams[0, 1] = Functions.GetAliasPath();
this.PageImage.QueryParameters = queryParams;

I tried this in the Page_Init and Page_Load just to test. Same results.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/11/2008 6:29:20 AM
   
RE:Can't get QueryParameters to work
Hi again,

I am sorry for the confusion - my previous post was not correct.

Could you please try to add to the query repeater in the ASPX code this parameter:

StopProcessing="true"

And then, in the code behind:

// Send in the Alias Path as a parameter to the query
object[,] queryParams = new object[1, 3];
queryParams[0, 0] = "@AliasPath";
queryParams[0, 1] = Functions.GetAliasPath();
this.QueryRepeater1.QueryParameters = queryParams;

this.QueryRepeater1.StopProcessing = false;
this.QueryRepeater1.ReloadData(false);


I hope this will be working fine now.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
danielrichard-oaot - 11/12/2008 6:14:08 AM
   
RE:Can't get QueryParameters to work
There were no errors, but unfortunately that only made the repeater stop displaying in the page altogether. I checked the rendered code and the control does not exist on the page when setting StopProcessing to true.

I tested my query by hard-coding in a value instead of using the @AliasPath parameter and the SQL functions correctly. All the options I've tried work except trying to use a parameter that I pass in.

Within the Queries tab, do I have access to get the current alias path of the page instead of passing it through a query parameter? For example, in a Transformation I could use <%# GetDocumentUrl() %>.

I also tried passing the alias path in through the ##WHERE## condition. But there must be some logic that you can only use that in an actual Where clause since when I tried to use it as a regular string (assigning to a variable in SQL), it keeps returning 1=1.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/13/2008 3:17:37 AM
   
RE:Can't get QueryParameters to work
Hi,

I hope this will finally work :-)

I have placed an image (cms.file) underneath the home page. On the home.aspx page is placed the query repeater like follows:

<cms:QueryRepeater ID="QueryRepeater1" runat="server" SelectTopN="1" TransformationName="CMS.File.ImageGallery_detail400" QueryName="cms.file.selectPageImage" StopProcessing="true"> </cms:QueryRepeater>

Then, in the query I have used the query "selectlattachments" and I have added to this "AND NodeAliasPath LIKE @AliasPath"

In the code behind of the page (PAge_Load() method) I have this code:

// Send in the Alias Path as a parameter to the query
object[,] queryParams = new object[1, 3];
queryParams[0, 0] = "@AliasPath";
queryParams[0, 1] = Functions.GetAliasPath() + "/%";
this.QueryRepeater1.QueryParameters = queryParams;
this.QueryRepeater1.StopProcessing = false;
this.QueryRepeater1.ReloadData(true);

Please notice that the ReloadData is set to true (I do not know why there is false in my previous post - I am sorry for that). Moreover, I had to add "/%" to the alias path so the repeater is listing the items underneath the home page.

I hope it will help.

Best Regards,
Juraj Ondrus

And when I view the home page, the image is displayed.

User avatar
Member
Member
danielrichard-oaot - 11/13/2008 9:40:07 AM
   
RE:Can't get QueryParameters to work
I copied your steps to the letter and it worked. So I slowly migrated back to my SQL statement and putting the code in the Master file. It all works now. I think the key was the StopProcessing.... but mistakenly setting the ReloadData to False made it break.

So, just out of curiousity, why is the StopProcessing required for this to work?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/14/2008 7:51:16 AM
   
RE:Can't get QueryParameters to work
Hi,

I am sorry once again for the "false" value mistake made by me.

StopProcessing is used because in the repeater's life cycle are not present the data you have set for the parameter at that time and the repeater will try to execute the query without the parameter. Also, it avoids running the query twice.

I hope it makes sense.

Best Regards,
Juraj Ondrus