Solved

500 points --- Retrieving value from Iframe

Posted on 2004-09-15
11
335 Views
Last Modified: 2013-12-16
Hi, I am an ASP Programmer and now just started learning ASP.Net with Vb.Net.

I am trying to put the value of an iframe from WYSIWYG editor, to SQL database, but I am not able to retrieve value from Iframe. Can anyone tell me what is the way to retrieve the value from Iframe, as in ASP it was Request.form("field_name").

Please make suggestions ASAP.

Khurram.
0
Comment
Question by:khurram007
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 8

Expert Comment

by:shovavnik
ID: 12062088
I'm not quite sure how you're trying to retrieve the value.

It is impossible, both with asp and asp.net to retrieve values directly from an iframe on the server-side.

One solution is to use javascript to update a textbox on the containing frame whenever the text is modified in the editor.  Then, when you post back, you can use the value from your textbox.  Just make sure your textbox is multiline, and invisible.
0
 
LVL 2

Author Comment

by:khurram007
ID: 12062571
I am not that good in Javascript... can you provide me a working sample?
0
 
LVL 5

Expert Comment

by:fahimnxb
ID: 12063078
Dear khurram,

A working sample might be provided, please give us some of you source/html.

Regards,
Me
0
 
LVL 2

Author Comment

by:khurram007
ID: 12063101
Just provide me sample showing how to transfer iframe value to a hidden text field and then retrieving on other page.
0
 
LVL 6

Expert Comment

by:zulu_11
ID: 12063239
U cannot get values from an IFRAME windows...it's not allowed..
If the framed site is not yours (from the same domain as the top domain), you can't know where user is going and what user is doing. This is built in security feature of the browser.

Zulu
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 2

Author Comment

by:khurram007
ID: 12063256
I am building the site myself. So no security issue should be there.

The question now is how to transfer iframe value to a hidden text field and then retrieving on other page??? and need a sample code doing that... Remember I am using Iframe for a WYSIWYG editor.

And one more question. I have WYSIWYG editors which use javascript and html text area. Can they work in Asp.net???
0
 
LVL 6

Expert Comment

by:zulu_11
ID: 12063360
try this...
since you are making this site yourself...use javascript to write the value of the field you want in a cookie..and then from the other page where you want to read this value..again use javascript to read the cookie value..
and yes..javascript and textarea work in ASP.NET

here are some sites which can help u with this

http://www.quirksmode.org/js/cookies.html

http://www.tutorialized.com/forum/viewtopic.php?t=400

Zulu
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12067374
What do you mean by getting the "value" from an <iframe>.  If you mean getting the URL of the page showing in the frame, first make the <iframe> a server control by doing this:

<iframe id="frmName" runat="server" src="http://www.someurl.com"></iframe>

This will cause ASP.NET to declare a variable to the HtmlGenericControl class for the iframe.  The variable will be whatever you put in the id="..." attribute.  Then get that value in code like this:

string frameURL = frmName.Attributes["src"]

You can then save that to a database.

John
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12067407
Note, however, this will only get the *original* URL loaded when the page loaded.  I don't think it will get the current URL if the user has navigated elsewhere.

John
0
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 total points
ID: 12084253
khurram, here's a rough-draft of a working example of what I meant.

ContainingPage.aspx:
<form runat="server" ...>
  <asp:TextBox runat="server" id="MyText" TextMode="Multiline" style="display:none;visibility:hidden;"></asp:TextBox>
  <iframe id="MyEditorFrame" src="MyEditor.aspx"></iframe>
</form>

Make sure to add a TextChanged event to your MyText control.  It will be called on post back when the editor in the iframe (below) is modified.

MyEditor.aspx:
<head>
<script>
  function updateText( obj )
  {
    var container = window.parent; // you can also use "top" if your container is the root frame
    var textbox = container.document.getElementById( 'MyText' );
    textbox.value = obj.value;
    // if the above line doesn't work, then try:
    // textbox.innerText = obj.innerText;
  }
</script>
<body>
<form runat="server" ...>
  <!-- all the html code for the editor -->
  <!-- on the textbox itself, which will be either an asp:TextBox with textmode set to multiline or a Textarea control
         (which are essentially identical), you need to have an onchange, or an onblur event: -->
  <textarea id="MyTextArea" onchange="updateText(this);"></textarea>
</form>
</body>

Note that this page does not need to post back ever.  Nor do you need a separate button to propogate the update to the parent frame.  It happens automatically when the user edits text in the editor.  If it works too slow (it shouldn't!) then respond to the onblur event instead of the onchange event.  The onblur event is only fired when the control loses focus, so it may be a bit less reliable, but will prevent it from being slow (which it should not be anyway).


Let me know if I can clarify on any part of this solution.
0
 
LVL 8

Expert Comment

by:shovavnik
ID: 12084286
By the way, this is standard javascript, and does not in itself have any security issues (as far as I know).

The only thing you need to be careful of, regardless of the solution you implement, is that the users can put dangerous javascript in your textarea in your editor.  You'll need to either do validation, to make sure there's no <script> element in the user-entered code, or enable the safeguard in your web.config.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now