0

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?

4
  • 2
    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.. Jun 5, 2014 at 6:24
  • Ok. Let me try. Jun 5, 2014 at 6:31
  • @ArsalanAdamKhatri Thank you so much. It worked. I was stuck in that by more than 24hours. Thank you again. Jun 5, 2014 at 6:37
  • I'm posting it as answer, please mark it correct to close the question.. Glad it helped.. :) Jun 5, 2014 at 7:54

1 Answer 1

1

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..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.