I have issue with SP.UI.ModalDialog.showModalDialog
. I am working on SharePoint 2010 web-part. In that I need to open the page in SharePoint custom popup. So I have used "SP.UI.ModalDialog.showModalDialog
" in my C# code behind file.
My code is as follows:
protected void btn_exptToWebPage_Click(object sender, ImageClickEventArgs e)
{
string url = string.Empty;
string qry = string.Empty;
if (!String.IsNullOrEmpty(Query))
{
qry = Query.Replace("/", "%2F");
qry = qry.Replace("<", "lt;");
qry = qry.Replace(">", "gt;");
url = SPContext.Current.Web.Url + "/_layouts/Share_List_Report_Solution/MainViewPage.aspx?listName=" + ShareListReportSolution.ListName + "|" + qry + "|" + ShareListReportSolution.ListValue;
}
else
{
url = SPContext.Current.Web.Url + "/_layouts/Share_List_Report_Solution/MainViewPage.aspx?listName=" + ShareListReportSolution.ListName + "|" + ShareListReportSolution.ListValue;
}
ScriptManager.RegisterClientScriptBlock(upPanel, upPanel.GetType(), "Succeed", "SP.UI.ModalDialog.showModalDialog({url:'" + url + "', title:'Running Profile'});", true);
}
The issue I am facing is when I pass Query (which is CAML Query) in URL it want work and gives java script error.:
Message: Expected '}'
Line: 62225345 //(Varies every time)
Char: 183
Code: 0
URI: http://myserver/SitePages/ShareList.aspx
And when the URL generates without caml query it works fine.
The URLs are as follows:
1) With CAML Query:
http://myserver/_layouts/Share_List_Report_Solution/MainViewPage.aspx?listName=TestList_Share|lt;Wheregt;lt;Containsgt;lt;FieldRef Name='MetaData' %2Fgt;lt;Value Type='Text'gt;Classlt;%2FValuegt;lt;%2FContainsgt;lt;%2FWheregt;|Title~Text,Multiline~Note,DateOnly~DateTime,PersonGroup~User,MetaData~TaxonomyFieldType&BackUrl=http://myserver/SitePages/ShareList.aspx
2) Without CAML Query:
http://myserver/_layouts/Share_List_Report_Solution/MainViewPage.aspx?listName=TestList_Share|Title~Text,Multiline~Note,DateOnly~DateTime,PersonGroup~User,MetaData~TaxonomyFieldType&BackUrl=http://myserver/SitePages/ShareList.aspx
If I copy and paste the URL with caml query in browser directly it opens the page. But from ModelDialog it gives the error. Can anyone help me to resolve this issue?
Name='MetaData'
is the culprit.. the single quote used in Field Name actually closes the URL block.. you might need to consider playing with"
and'
to fix this..