[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 889
  • Last Modified:

Modal popup in Sharepoint not rendering > or < properly

Hi
I have a web part which displays a gridview of data (each row shows data about a document - title, publication date, author etc etc)

The cell with the title is a link which opens a modal popup which displays some text.
That works fine.
The problem is if I try to do something like ...

Label popupText = WebPart.Factory.CreateLabel("<iframe src='news.html' width='40%' height='80' align='right'><p>See our <a href='news.html'>newsflashes</a>.</p></iframe>", "", popupContentPanel);


it renders as ...

&lt;iframe src=&#39;news.html&#39; width=&#39;40%&#39; height=&#39;80&#39; align=&#39;right&#39;&gt;&lt;p&gt;See our &lt;a href=&#39;news.html&#39;&gt;newsflashes&lt;/a&gt;.&lt;/p&gt;&lt;/iframe&gt;

Any ideas?
TableRow resultTableRow = WebPart.Factory.CreateTableRow(TemplateCssSuffix("resultTableRow"), resultTable);
                    {
                        // title
                        TableCell titleTableCell = WebPart.Factory.CreateTableCell(TemplateCssSuffix("titleTableCell"), resultTableRow);
                        {
                            //link that fires the modal...
                            HyperLink hlTitleFireModal = WebPart.Factory.CreateHyperlink("", string.Empty, string.Empty, false, "imageLink", titleTableCell);
                            hlTitleFireModal.DataBinding += new EventHandler(hlTitleFireModal_DataBinding);

                            Panel popupPanel;
                            Panel popupContentPanel;

                            popupContentPanel = WebPart.Factory.CreateBasicPopupPanel(hlTitleFireModal, titleTableCell, out popupPanel);
                            {
                                Image popupImage = WebPart.Factory.CreateImage("", "popupImage", popupContentPanel);
                                Label popupText = WebPart.Factory.CreateLabel("<iframe src='news.html' width='40%' height='80' align='right'><p>See our <a href='news.html'>newsflashes</a>.</p></iframe>", "", popupContentPanel);
                            }

                        }

Open in new window

0
hmcgeehan
Asked:
hmcgeehan
  • 7
  • 5
1 Solution
 
anvCommented:
try using server.htmlencode("iframe string here")
0
 
hmcgeehanAuthor Commented:
I try

                                Label popupText = WebPart.Factory.CreateLabel(Server.HtmlEncode("<iframe src='http://intranet' width='40%' height='80' align='right'></iframe>"), "", popupContentPanel);


Error      4      The name 'Server' does not exist in the current context      
0
 
hmcgeehanAuthor Commented:
and if i try

                                Label popupText = WebPart.Factory.CreateLabel(HttpContext.Current.Server.HtmlEncode("<iframe src='http://intranet' width='40%' height='80' align='right'></iframe>"), "", popupContentPanel);

i get

Error      4      The name 'HttpContext' does not exist in the current context
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
anvCommented:
try SPEncode.HtmlEncode
0
 
hmcgeehanAuthor Commented:
Thanks

Here's what it looks like now when I click on the link ....


iframe-on-modal.jpg
0
 
anvCommented:
try passing the same string and removing encode

pass only "<iframe src=&#39;news.html&#39; width=&#39;40%&#39; height=&#39;80&#39; align=&#39;right&#39;><p>See our <a href=&#39;news.html&#39;>newsflashes</a>.</p></iframe>" without encode.
0
 
hmcgeehanAuthor Commented:
that gives me ...


iframe-on-modal2.jpg
0
 
anvCommented:
cannot we create an IFrame directly instead of Label?
0
 
hmcgeehanAuthor Commented:
I think it the only way is with  
WebPart.Factory.CreateLabel
but I could be wrong.

The thing is if I do
Label popupText = WebPart.Factory.CreateLabel("<table><tr><td>test</td></tr></table>", "", popupContentPanel);
that it displays the text "<table><tr><td>test</td></tr></table>" but it doesn't render the table.

It doesn't interprete the tags.

Any ideas?
thanks
TableRow resultTableRow = WebPart.Factory.CreateTableRow(TemplateCssSuffix("resultTableRow"), resultTable);
                    {
                        // title
                        TableCell titleTableCell = WebPart.Factory.CreateTableCell(TemplateCssSuffix("titleTableCell"), resultTableRow);
                        {
                            //link that fires the modal...
                            HyperLink hlTitleFireModal = WebPart.Factory.CreateHyperlink("", string.Empty, string.Empty, false, "imageLink", titleTableCell);
                            hlTitleFireModal.DataBinding += new EventHandler(hlTitleFireModal_DataBinding);

                            Panel popupPanel;
                            Panel popupContentPanel;

                            popupContentPanel = WebPart.Factory.CreateBasicPopupPanel(hlTitleFireModal, titleTableCell, out popupPanel);
                            {
                                Image popupImage = WebPart.Factory.CreateImage("", "popupImage", popupContentPanel);
                                //Label popupText = WebPart.Factory.CreateLabel(SPEncode.HtmlEncode("<iframe src='http://intranet' width='40%' height='80' align='right'></iframe>"), "", popupContentPanel);
                                
                                Label popupText = WebPart.Factory.CreateLabel(thePopupText, "", popupContentPanel);
                            }

Open in new window

0
 
hmcgeehanAuthor Commented:
i meant to include this ...

public Label CreateLabel(string labelText, string cssSuffix, Control controlToAddTo)
        {
            return CreateLabel(labelText, cssSuffix, controlToAddTo, false);
        }





public Label CreateLabel(string labelText, string cssSuffix,
            Control controlToAddTo, bool isGeneric)
        {
            Label label = new Label();

            if (IsStyledText(labelText))
            {
                label.Text = labelText;
            }
            else
            {
                label.Text = SPEncode.HtmlEncode(labelText);
            }
            ConfigureControl(label, cssSuffix, controlToAddTo, isGeneric);
            return label;
        }
0
 
anvCommented:
Try using HTMLGeneric control with span tag and using innerhtml to assign the data, if that works.
0
 
hmcgeehanAuthor Commented:
I got it with this ...
//link that fires the modal...
            imageLink = Factory.CreateHyperlink(string.Empty, string.Empty, string.Empty, false, "imageLink", containerPanel);

            //postLinkLabel = Factory.CreateLabel(string.Empty, "postLinkSpan", containerPanel);

            Panel popupPanel;
            Panel popupContentPanel;

            popupContentPanel = Factory.CreateBasicPopupPanel(imageLink, containerPanel, out popupPanel);
            {
                popupImage = Factory.CreateImage("", "popupImage", popupContentPanel);
                popupText = Factory.CreateLabel("testing!", "", popupContentPanel);
            }

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now