Click here to Skip to main content
Click here to Skip to main content

How to get the HTML source code from an editable Iframe, on the server.

, 25 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Getting the HTML source code from an editable Iframe, on the server

Introduction

There are some times when you want to obtain the HTML source code from an editable Iframe, on the server side of the world, and this article gives a very simple example of that.

The ASP.NET form

<%@ Page Language="vb" AutoEventWireup="false" 
                Codebehind="test.aspx.vb" Inherits="test"%>
<form id=frmMain method=post runat="server">
    <iframe id=ifrHTML name=ifrHTML runat="server"></iframe>
    <asp:Button id=cmdSend runat="server" Text="Send"></asp:Button>
    <input type=hidden name=hidValue>
</form>
<script>
    //Set the IFRame to Desing Mode.
    ifrHTML.document.designMode = "on";            
</script>

As you can see from the code above we have the Iframe, a submit button, and a hidden field.

We will need the hidden field to store the value of the innerHTML value of the Iframe in the client side, so we can submit later the hidden field into the server side code.

CodeBehind

Private Sub Page_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
    cmdSubmit.Attributes.Add("onClick", _
       "document.frmMain.hidValue.value = ifrHTML.document.body.innerHTML;")
End Sub

Private Sub cmdSubmit_Click(ByVal sender As System.Object,_
     ByVal e As System.EventArgs) Handles cmdSubmit.Click
    Dim strValue As String

    strValue = Request.Form("hidValue")
End Sub

First we'll take a look at the Page_Load function. As you can see there's just a simple attribute addition to the cmdSubmit button. We added the onClick event, so whenever the user clicks this button, the value of the HTML source within the editable Iframe, will be stored on the hidden field hidValue.

Now the cmdSubmit_Click event. Here's where we actually get the HTML source that the Iframe passed to the hidden field on the client side, and we get it by a simple Request.Form of the hidden field, and store it into the string variable strValue.

That's it, you now have the HTML source code of an editable Iframe into a string variable on the server.

Conclusion

There are many ways of storing the HTML source code of an Iframe into the server side, this is just one of them. I hope you find it useful.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Hugo Flores
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralThanks! But in FireFox a little bit different... PinmemberEnigmatic22-Jan-09 1:44 
QuestionHow to display an html file inside Iframe --need urgent help PinmemberVishnu Narayan Mishra15-Nov-07 20:00 
Questionhow to dynamically refresh iframe when hosting through IIS Pinmembernaresh26930-Oct-07 0:01 
GeneralReceiving Nothing PinmemberThe Knowledge8-Sep-07 5:34 
GeneralC# PinmemberManhhm2-Apr-06 19:31 
GeneralRe: C# PinmemberHugo Flores11-Apr-06 7:43 
GeneralEmpty String, doesn't work. Pinmemberbswiftly14-Sep-04 5:10 
GeneralRe: Empty String, doesn't work. PinmemberHugo Flores14-Sep-04 5:31 
GeneralRe: Empty String, doesn't work. Pinmemberbswiftly14-Sep-04 5:46 
GeneralRe: Empty String, doesn't work. PinmemberHugo Flores14-Sep-04 6:38 
GeneralRe: Empty String, doesn't work. Pinmemberbswiftly14-Sep-04 9:46 
GeneralRe: Empty String, doesn't work. Pinmemberbswiftly14-Sep-04 9:54 
GeneralRe: Empty String, doesn't work. PinmemberHugo Flores14-Sep-04 10:43 
GeneralRe: Empty String, doesn't work. PinmemberHugo Flores14-Sep-04 10:38 
GeneralRe: Empty String, doesn't work. Pinmemberbswiftly14-Sep-04 10:50 
GeneralRe: Empty String, doesn't work. Pinmemberbswiftly14-Sep-04 15:45 
GeneralRe: Empty String, doesn't work. PinmemberHugo Flores15-Sep-04 2:31 
GeneralRe: Empty String, doesn't work. Pinmemberbswiftly15-Sep-04 4:35 
GeneralRe: Access Denied Pinmemberbswiftly15-Sep-04 13:12 
ahh..
 
sorry.. noticed one thing.
 
Says Access denied when I load the page that is JUST your code.
 
Line 23, char. 5. was using a variety of sites to test an dthey all had the same error.
 
I tried this on xp, and win2000
GeneralRe: Access Denied PinmemberHugo Flores16-Sep-04 3:50 
GeneralRe: Access Denied Pinmemberbswiftly16-Sep-04 13:05 
GeneralDoes Not Accept Formatting of Text PinsussL anthony Johnson20-Nov-03 11:08 
QuestionAnd what about putting source on an IFrame? PinmemberNuno Ferro9-Sep-03 8:04 
AnswerRe: And what about putting source on an IFrame? PinmemberHugo Flores9-Sep-03 8:17 
GeneralRe: And what about putting source on an IFrame? PinmemberNuno Ferro9-Sep-03 8:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 26 Mar 2003
Article Copyright 2003 by Hugo Flores
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid