ASPX templates
Version 4.x > ASPX templates > QueryString Parameters and Generic templates View modes: 
User avatar
Member
Member
srizzetto-microgate - 11/16/2009 7:35:05 AM
   
QueryString Parameters and Generic templates
HI, I have two question… (for version 4.1)

1) Is it possible to add one or more QueryString parameters to a Menu ? Eg. I create a page document called “Mypage” but I want that the menu is rendered with querystring params like
“mypage.aspx?par1=aaa&par2=1”


2) Instead to use querystring parameters, would be possible to create generic templates with placeholders variables and then substitute at runtime with the right values ?
Eg. Suppose I want to create a generic template that show an image; I would like to write the template like
<img src=”{file}” width=”{width}” height=”{height}” />

And then somewhere I should fill the 3 variables (the placeholder { } could be < > or <%# %> ) etc.
Maybe I have an example to show me…
Thanks a lot and best regards

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/24/2009 1:26:29 PM
   
RE:QueryString Parameters and Generic templates
Hi,

I already answered this over the e-mail, so I will copy it here too for reference for other users.

Yes, you can use multiple query string parameters.

You can also add the macros to the IMG tag in the HTML. But we do not think that it is safe, let s say for the IMG tag:

<img src=”{file}” width=”{width}” height=”{height}” />

someone can add to the query string ending tag and add javascript to it to execute code on your page. I would not recommend to use it in this way.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
srizzetto-microgate - 11/25/2009 2:49:12 AM
   
RE:QueryString Parameters and Generic templates
I understand the risk of script injection, but a part of this, I don't understand how to implement this type of macro in a aspx template...

Suppose I create a page template with that <img> tag called template.aspx and I register it in my site
In the code behind how can I bind the Request.QueryString["file"].ToString() value to {file} ?
Or have I to use the normal syntax <%# file %> and then use Page.DataBind() ?

Second:
Then I create a document (mypage.aspx) based on that template...

The cmsList control renders the menu item as href="mypage.aspx"
How can I force the control to render with my qs parameters ?

What I miss is a field where to put the querystring; having that field then I can change the ascx control or create a new one...

Thanks

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/27/2009 2:27:45 AM
   
RE:QueryString Parameters and Generic templates
Hi again,

I assume that you are using ASPX page templates. In this case you can access the query string in code behind, so you can evaluate the values using your code and there is no need for special macros. Or, as you mention you can use <%# file %>, but I would recommend to use "=" instead of "#".

Regarding the second one - you need to access the rendered HTML code property of the menu web part and change it according to your needs.

Best Regards,
Juraj Ondrus