Fit2Page
asked on 08 May 2025, 11:19 AM
| edited on 08 May 2025, 11:20 AM
In my Standalone Image manager I encounter the following: When using StandAlone.AdditionalQueryString = "&PreselectedItemUrl=xxxxxxxx" in combination with File Explorer paging the correct image is not selected. Is there any workaround for this?
Thanks,
Marc
1 Answer, 1 is accepted
0
Rumen
Telerik team
answered on 12 May 2025, 12:14 PM
| edited on 12 May 2025, 12:55 PM
The PreselectedItemUrl is a QueryString parameter that should be added to the DialogOpener using its set_additionalQueryString() client-side method,e.g.:
<scripttype="text/javascript">var oldAdditionalQueryString = null;
functionOpenImgManager() {
var dialogOpener = $find('<%= DialogOpener1.ClientID %>');
var args = new Telerik.Web.UI.EditorCommandEventArgs("ImageManager", null, document.createElement("img"));
var txt = $get('<%= TextBox1.ClientID %>');
var itemUrl = "/Images/animal.png"; //path to the image//add an if check if the txt box is empty set the default itemUrl from above, otherwise set the new textbox value by extracting the src path from the img tagif (txt.value != "") {
var imgTag = txt.value;
// Extract src value using regexvar match = imgTag.match(/src=['"]?([^'"]+)['"]?/i);
if (match && match[1]) {
var src = match[1];
// Remove domain if presentif (src.indexOf(window.location.origin) === 0) {
src = src.substring(window.location.origin.length);
}
// Ensure it starts with /if (src.charAt(0) !== "/") {
src = "/" + src;
}
itemUrl = src;
}
}
var currentQueryString = dialogOpener.get_additionalQueryString();//get predefined query string
oldAdditionalQueryString = currentQueryString;
dialogOpener.set_additionalQueryString(currentQueryString + "&PreselectedItemUrl=" + itemUrl);//add the PreselectedITemUrl parameter
args.CssClasses = [];
dialogOpener.open('ImageManager', args);
dialogOpener.set_additionalQueryString(currentQueryString + "&PreselectedItemUrl=" + itemUrl);//add the PreselectedITemUrl parameter
dialogOpener.set_additionalQueryString(oldAdditionalQueryString);
oldAdditionalQueryString = null;
}
functionImageManagerFunction(sender, args) {
if (!args) {
alert('No file was selected!');
returnfalse;
}
var path = args.get_value()[0].src;
var txt = $get('<%= TextBox1.ClientID %>');
txt.value = "<img src='" + path + "' />";
}
</script><asp:TextBoxrunat="server"ID="TextBox1"Width="400px"></asp:TextBox><br /><telerik:DialogOpenerRenderMode="Lightweight"runat="server"ID="DialogOpener1"></telerik:DialogOpener><buttononclick="OpenImgManager();return false;">Open ImageManager</button>
I tested this solution and verified that it works as expected in a paging scenario with multiple pages and files.
It appears now that the problem we had was due to the fact that the value of the PreselectedItemUrl parameter is case-sensitive. As IIS and Windows folder system are not case-sensitive, shouldn't this be re-factored?
Regards,
Marc
Rumen
Telerik team
commented on 14 May 2025, 02:18 PM
Thank you for the follow-up and for identifying the cause of the issue.
You're absolutely right - the case sensitivity of the PreselectedItemUrl parameter can lead to unexpected behavior, especially given that IIS and the Windows file system are not case-sensitive by default. This inconsistency could indeed be confusing. As a workaround, I'd suggest normalizing the casing of the URLs used in the PreselectedItemUrl parameter to ensure consistency with how the paths are stored or returned in your application.