all posts

Am I a bad person for doing this?

Published to Blog on 13 Jan 2005

I was just working on a page and I needed to be able to do some sort of preview of the rendered HTML entered into a textbox when the user pressed the preview button.  I really don’t want to leave the page that I’m on so I thought about popping up another window.  But I was left with the problem of how to get the content from the text box into the popup page.  I could have probably written some nice little javascript that would do some cool innerHTML stuff, but I wanted something a little easier.

I decided to think about the problem a little more and thought that an iframe might be a solution.  I keep the iframe hidden until the preview button is clicked and then poof it magically appears with the rendered content inside it!  Ahhh, but I still had the same problem I had earlier - getting the text from the textbox into the page.  Darn it!  Unfortunately there is no easy way to pass text into an iframe.  Microsoft should create a new server control for ASP.NET 2.0 that renders an iframe in the browser and has a .text property !!

I decide that I like the idea of using the iframe so I make my page, preview.aspx that will serve as my page inside of the iframe.  How do I pass the content into this page?  How do I do it?  I could use the querystring.  Nah - you can’t do that - it’s just not right.  You can’t pass a whole bunch of stuff like that throught the querystring.  Aw hell with it - why not !?!?

So I add a literal control to the page and then in the code behind I just assign the value that was passed through the querystring to the .text property of the literal.

On the parent page I add a literal and make it not visible.  Then I added code so that when the preview button is pressed the .text property of the literal on that page is set to something like “<iframe src=”preview.aspx?text=” & mycontent to display & “>” and the literal is made visible.  Worked out well, though not really elegant.

Am I a bad person for passing a bunch of text like that through the querystring?  Should I change my code to use some nifty javascript instead?

I wonder if I was using Whidbey if it would throw a “shitty code exception“?

Dan Hounshell
Web geek, nerd, amateur maker. Likes: apis, node, motorcycles, sports, chickens, watches, food, Nashville, Savannah, Cincinnati and family.
Dan Hounshell on Twitter