开发者

Can't insert data from SQL to a div's html in ASP.NET

When i try to insert html text into a div (i made it runat=server and i populate the div with html text. it's look like this,

string htmlData = "< html > blabla...< /html >";
divcontent.innerHtml = htmlData;开发者_开发问答

the page is damaged.

but when i take the same html data and put it as is in an html file its shows properly. what should i take in consider ?

p.s. i am writing in asp.net (c#) VS2005.


HTML is the root element and you are only allowed to have it once.

See here.

Try replacing <html> with a <div>

string htmlData = "<div> blabla...< /div>"; 
divcontent.innerHtml = htmlData;

Based on the comment. This is how you can use an IFrame and set it. I have no idea if this works in all broswers. My advice is rethink your solution to make sure you are required to have all the header information.

<html>

    Hello this will have an IFrame

    <br /><br /><br />

    <iframe id="myFrame">
        If you see this message get a new broswer.
    </iframe>

    <script>

        var myFrame = document.getElementById('myFrame');

        if(myFrame != null)
        {
            myFrame.contentWindow.document.write('<html><span>Hello World</span><html>');
        }
        else
        {
            alet('Did not find FRAME');
        }

    </script>

</html>


Could you paste what the "blabla...." is? If you are trying to paste a whole HTML document (with HEAD, BODY tags etc) into a div it might do something weird to your page. You should be putting an HTML fragment into the div. Is that what you are doing?


I don't believe you can use HTML like that, since the DIV is inside the body already.

You will need to split up the string into the correct HTML tags..

pull out the header and put it into a header string and same with the body

I've done something similar, but I saved the Header tags into a string and body in a seperate string then displayed them in the proper places


i found the soultion to my problem. i needed to remove the DOCTYPE tag from my page. it causes a contradiction with my html string. i dont know what to replace it with but it works for me...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜