Solved

500 points --- Retrieving value from Iframe

Posted on 2004-09-15
11
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

691 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