Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We can include ascx files in web parts

 private const string _ascxPath = @"~/_CONTROLTEMPLATES/TestPart/Test.ascx";
 protected override void CreateChildControls()
    {
        Control control = Page.LoadControl(_htmlPath);
        Controls.Add(control);
    }

I want to include Xhtml file in my web part , how i can make it ? it's makes error when i replace Test.ascx file into my test.xhtml file

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Xhtml are not controls. Thus, you can't use LoadControl.

What you want, if my understanding is correct, is to include some Xhtml content in the page. The easiest way is to use a Literal control :

protected override void CreateChildControls()
{
     var literal = new Literal();
     literal.Text = xhtmlContent;
     Controls.Add(literal);
}

Do not forget that there is an OOB wepart (content webpart) that allows you to render content, either from a string in the property of the webpart or an url. It may be far less compless to deploy (depending on your needs).

Another thing to take into consideration is the potential script injection attack possible with this code. Can you trust the xhtmlContent content ? If it's a user input, you will expose the SharePoint farm at risk.

A final though. Here it's more a ASP.Net problem than a SharePoint one. You should start by learning ASP.Net as SharePoint requires a deep understanding of ASP.Net internal's.

share|improve this answer
    
Thanks Steve for replay .. it's not user input content . I will consider your advice by learning ASP.Net –  l_beka_l Mar 20 '12 at 11:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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