Best way to dump HTML strings to a page in ASP.Net?

M

mathewda

I'm currently work'n on a project where I'm dynamically generating some
HTML as text into a string builder. My ASP page has a <span> tag on it
and after I gernerate HTML to my string builder I concat all the
strings and set the span's innerHTML property to this output. What I'm
wondering is if this is the best way to do this or is there a better
method to take a bunch of strings and dump them out onto an ASP page so
it shows up as formatted HTML? Second of all, this method seems to work
fine when my text has a lower number of strings, if I have a lot of
strings however it outputs to the page correctly but strangely enough
other portions of my page stop working (like my seach box will no
longer work, this only happens with a high number of strings being
concat'ed though, like 100+)? Any insights would be appreciated!
 
D

Dave Mathew

yeah, a literal seems to be a better way to go.

However, even after I switched it to that I'm still having problems
with how much HTML I'm allowed to post to the text property of the
literal. Is there some kinda of limit on how much data you can assign
to the text property?

Here's the specific effect I'm seeing.... I have a custom built seach
box which is simply a button and a text box which has an OnClick method
that uses Response.Redirect to redirect to a URL adding a query string.
On this results page I have a asp:Literal tag and I generate a bunuch
of HTML as strings into a string builder. After all my strings are
generated I say nameOfLiteral.Text = nameOfStringBuilder.ToString();
The page always shows the correct dynamically generated HTML so it
seems the data is getting into the text property of the Literal and
displayed on the page... however, when I don't have that much HTML
added to the Literal my search box works as normal, when I add much
more HTML to the literal control my search box stops working and
generates a scrip error in IE. So it seems as if the text is getting to
the literal ok but for some reason a lot of text as opposed to a little
breaks my page. Any suggestions on a fix for this?
 
D

Dave Mathew

k, I got it figured out now, or at least a solution with a plausable
explaination. Thought I'd repost in case anybody else has this problem
in the future. I tried running my page in FireFox and it worked there
but not in IE. After a little research it seems that IE has different
limitations for query strings or hidden fields than other browers...
apparently FireFox supports more data than IE in this respect which
would explain why it worked in FireFox but not in IE. Because I was
using GET for the form method this also made a difference (again
seemingly a difference between browsers). By changing the the form
method to POST (which is generally used for larger amounts of data) the
problem was solved in IE. Moral of the story is that if there's a lot
of data being passed in a query string or hidden feild make sure your
form method is POST so it has more room to pass your data along.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top